Product Promotion
0x5a.live
for different kinds of informations and explorations.
GitHub - usk81/generic: flexible data type for Go
flexible data type for Go. Contribute to usk81/generic development by creating an account on GitHub.
Visit SiteGitHub - usk81/generic: flexible data type for Go
flexible data type for Go. Contribute to usk81/generic development by creating an account on GitHub.
Powered by 0x5a.live ๐
Generic
flexible data type for Go
support: Go 1.12+
Install
standard go get
:
go get -u github.com/usk81/generic/v2
Usage
encode/decode:
package main
import (
"encoding/json"
"github.com/usk81/generic/v2"
)
type User struct {
Name String `json:"name"`
Age generic.Int `json:"age"`
}
var user1 User
u1 := []byte(`{"name":"Daryl Dixon","age":"40"}`)
json.Unmarshal([]byte(u1), &user1)
b, _ := json.Marshal(user1)
Println(string(b))
// {"name":"Daryl Dixon","age":40}
var user2 User
u2 := []byte(`{"name":"Rick Grimes"}`)
json.Unmarshal([]byte(u2), &user2)
b, _ := json.Marshal(user2)
Println(string(b))
// {"name":"Rick Grimes","age":null}
set:
package main
import (
"fmt"
"github.com/usk81/generic"
)
func main() {
v := 1.0
var tb generic.Bool
tb.Set(v)
vb := tb.Weak()
fmt.Printf("%v, (%T)\n", vb, vb)
// true, (bool)
var tf generic.Float
tf.Set(v)
vf := tf.Weak()
fmt.Printf("%v, (%T)\n", vf, vf)
// 1, (float64)
var ti generic.Int
ti.Set(v)
vi := ti.Weak()
fmt.Printf("%v, (%T)\n", vi, vi)
// 1, (int64)
var ts generic.String
ts.Set(v)
vs := ts.Weak()
fmt.Printf("%v, (%T)\n", vs, vs)
// 1, (string)
var tt generic.Time
tt.Set(v)
vt := tt.Weak()
fmt.Printf("%v, (%T)\n", vt.UTC(), vt)
// 1970-01-01 09:00:01 +0900 JST, (time.Time)
var tu generic.Uint
tu.Set(v)
vu := tu.Weak()
fmt.Printf("%v, (%T)\n", vu, vu)
// 1, (uint64)
}
Benchmarks
Marshal
Bool
version | requests | /op | B/op | allocs/op |
---|---|---|---|---|
1.0.0 | 5000000 | 240 ns | 185 | 3 |
2.0.0 | 200000000 | 6.69 ns | 0 | 0 |
Float
version | requests | /op | B/op | allocs/op |
---|---|---|---|---|
1.0.0 | 3000000 | 425 ns | 192 | 3 |
2.0.0 | 5000000 | 260 ns | 64 | 3 |
Int
version | requests | /op | B/op | allocs/op |
---|---|---|---|---|
1.0.0 | 5000000 | 265 ns | 192 | 3 |
2.0.0 | 20000000 | 70.5 ns | 16 | 2 |
String (small)
version | requests | /op | B/op | allocs/op |
---|---|---|---|---|
1.0.0 | 3000000 | 382 ns | 200 | 3 |
2.0.0 | 20000000 | 89.0 ns | 128 | 2 |
String (Large)
version | requests | /op | B/op | allocs/op |
---|---|---|---|---|
1.0.0 | 1000000 | 1056 ns | 776 | 4 |
2.0.0 | 5000000 | 237 ns | 896 | 2 |
Time
version | requests | /op | B/op | allocs/op |
---|---|---|---|---|
1.0.0 | 1000000 | 1122 ns | 360 | 5 |
2.0.0 | 3000000 | 401 ns | 48 | 1 |
TimestampMS
version | requests | /op | B/op | allocs/op |
---|---|---|---|---|
1.0.0 | 20000000 | 97.9 ns | 32 | 2 |
2.0.0 | 20000000 | 91.2 ns | 32 | 2 |
TimestampNano
version | requests | /op | B/op | allocs/op |
---|---|---|---|---|
1.0.0 | 10000000 | 114 ns | 64 | 2 |
2.0.0 | 10000000 | 112 ns | 64 | 2 |
Timestamp
version | requests | /op | B/op | allocs/op |
---|---|---|---|---|
1.0.0 | 20000000 | 88.4 ns | 32 | 2 |
2.0.0 | 20000000 | 86.7 ns | 32 | 2 |
Uint
version | requests | /op | B/op | allocs/op |
---|---|---|---|---|
1.0.0 | 5000000 | 277 ns | 192 | 3 |
2.0.0 | 20000000 | 64.2 ns | 16 | 2 |
Licence
Author
GoLang Resources
are all listed below.
GitHub - GuilhermeCaruso/anko: :crystal_ball: Simple application watcher
resource
~/github.com
resource
GitHub - jidicula/go-fuzz-action: GitHub Action for Go 1.18 fuzz testing
resource
~/github.com
resource
GitHub - tucnak/climax: Climax is an alternative CLI with the human face
resource
~/github.com
resource
GitHub - lawrencewoodman/roveralls: A Go recursive coverage testing tool
resource
~/github.com
resource
GitHub - nakagami/firebirdsql: Firebird RDBMS sql driver for Go (golang)
resource
~/github.com
resource
GitHub - liweiyi88/onedump: Effortlessly database dump with one command.
resource
~/github.com
resource
GitHub - beefsack/go-astar: Go implementation of the A* search algorithm
resource
~/github.com
resource
GitHub - lxn/walk: A Windows GUI toolkit for the Go Programming Language
resource
~/github.com
resource
GitHub - mongodb/mongo-go-driver: The Official Golang driver for MongoDB
resource
~/github.com
resource
GitHub - bykof/gostradamus: Gostradamus: Better DateTimes for Go ๐ฐ๏ธ
resource
~/github.com
resource
GitHub - mozillazg/go-unidecode: ASCII transliterations of Unicode text.
resource
~/github.com
resource
GitHub - bolknote/go-gd: Go bingings for GD (http://www.boutell.com/gd/)
resource
~/github.com
resource
GitHub - mosajjal/dnsmonster: Passive DNS Capture and Monitoring Toolkit
resource
~/github.com
resource
GitHub - haxpax/gosms: :mailbox_closed: Your own local SMS gateway in Go
resource
~/github.com
resource
GitHub - wajox/gobase: This is a simple skeleton for golang applications
resource
~/github.com
resource
GitHub - VividCortex/gohistogram: Streaming approximate histograms in Go
resource
~/github.com
resource
GitHub - malaschitz/randomForest: Random Forest implementation in golang
resource
~/github.com
resource
GitHub - google/gopacket: Provides packet processing capabilities for Go
resource
~/github.com
resource
GitHub - khezen/evoli: Genetic Algorithm and Particle Swarm Optimization
resource
~/github.com
resource
GitHub - didip/tollbooth: Simple middleware to rate-limit HTTP requests.
resource
~/github.com
resource
GitHub - mustafaakin/gongular: A different approach to Go web frameworks
resource
~/github.com
resource
GitHub - songgao/colorgo: Colorize (highlight) `go build` command output
resource
~/github.com
resource
Made with โค๏ธ
to provide different kinds of informations and resources.