{"id":13764133,"url":"https://github.com/usk81/generic","last_synced_at":"2025-04-10T08:30:54.471Z","repository":{"id":55037259,"uuid":"61212469","full_name":"usk81/generic","owner":"usk81","description":"flexible data type for Go","archived":false,"fork":false,"pushed_at":"2021-01-13T20:33:15.000Z","size":112,"stargazers_count":49,"open_issues_count":2,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T18:49:39.157Z","etag":null,"topics":["flexible-data","generic","go","golang","marshaller","types"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/usk81.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-15T14:00:36.000Z","updated_at":"2025-02-18T11:15:25.000Z","dependencies_parsed_at":"2022-08-14T09:50:21.077Z","dependency_job_id":null,"html_url":"https://github.com/usk81/generic","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usk81%2Fgeneric","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usk81%2Fgeneric/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usk81%2Fgeneric/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usk81%2Fgeneric/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usk81","download_url":"https://codeload.github.com/usk81/generic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248185261,"owners_count":21061483,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flexible-data","generic","go","golang","marshaller","types"],"created_at":"2024-08-03T15:01:15.259Z","updated_at":"2025-04-10T08:30:54.144Z","avatar_url":"https://github.com/usk81.png","language":"Go","readme":"# Generic\n[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square)](https://pkg.go.dev/github.com/usk81/generic)\n[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://github.com/usk81/generic/blob/master/LICENSE)\n![](https://github.com/usk81/generic/workflows/preliminary%20review/badge.svg)\n[![codecov](https://codecov.io/gh/usk81/generic/branch/master/graph/badge.svg)](https://codecov.io/gh/usk81/generic)\n[![Go Report Card](https://goreportcard.com/badge/github.com/usk81/generic)](https://goreportcard.com/report/github.com/usk81/generic)\n\nflexible data type for Go\n\nsupport: Go 1.12+\n\n## Install\n\nstandard `go get`:\n\n```\ngo get -u github.com/usk81/generic/v2\n```\n\n## Usage\n\nencode/decode:\n\n```go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"github.com/usk81/generic/v2\"\n)\n\ntype User struct {\n\tName String      `json:\"name\"`\n\tAge  generic.Int `json:\"age\"`\n}\n\nvar user1 User\nu1 := []byte(`{\"name\":\"Daryl Dixon\",\"age\":\"40\"}`)\njson.Unmarshal([]byte(u1), \u0026user1)\nb, _ := json.Marshal(user1)\nPrintln(string(b))\n// {\"name\":\"Daryl Dixon\",\"age\":40}\n\nvar user2 User\nu2 := []byte(`{\"name\":\"Rick Grimes\"}`)\njson.Unmarshal([]byte(u2), \u0026user2)\nb, _ := json.Marshal(user2)\nPrintln(string(b))\n// {\"name\":\"Rick Grimes\",\"age\":null}\n```\n\nset:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/usk81/generic\"\n)\n\nfunc main() {\n\tv := 1.0\n\n\tvar tb generic.Bool\n\ttb.Set(v)\n\tvb := tb.Weak()\n\tfmt.Printf(\"%v, (%T)\\n\", vb, vb)\n\t// true, (bool)\n\n\tvar tf generic.Float\n\ttf.Set(v)\n\tvf := tf.Weak()\n\tfmt.Printf(\"%v, (%T)\\n\", vf, vf)\n\t// 1, (float64)\n\n\tvar ti generic.Int\n\tti.Set(v)\n\tvi := ti.Weak()\n\tfmt.Printf(\"%v, (%T)\\n\", vi, vi)\n\t// 1, (int64)\n\n\tvar ts generic.String\n\tts.Set(v)\n\tvs := ts.Weak()\n\tfmt.Printf(\"%v, (%T)\\n\", vs, vs)\n\t// 1, (string)\n\n\tvar tt generic.Time\n\ttt.Set(v)\n\tvt := tt.Weak()\n\tfmt.Printf(\"%v, (%T)\\n\", vt.UTC(), vt)\n\t// 1970-01-01 09:00:01 +0900 JST, (time.Time)\n\n\tvar tu generic.Uint\n\ttu.Set(v)\n\tvu := tu.Weak()\n\tfmt.Printf(\"%v, (%T)\\n\", vu, vu)\n\t// 1, (uint64)\n}\n```\n\n## Benchmarks\n\n### Marshal\n\n#### Bool\n\n| version | requests | /op | B/op | allocs/op |\n|---|---|---|---|---|\n| 1.0.0  | 5000000 | 240 ns | 185 | 3 |\n| 2.0.0  | 200000000 | 6.69 ns | 0 | 0 |\n\n#### Float\n\n| version | requests | /op | B/op | allocs/op |\n|---|---|---|---|---|\n| 1.0.0  | 3000000 | 425 ns | 192 | 3 |\n| 2.0.0  | 5000000 | 260 ns | 64 | 3 |\n\n#### Int\n\n| version | requests | /op | B/op | allocs/op |\n|---|---|---|---|---|\n| 1.0.0  | 5000000 | 265 ns | 192 | 3 |\n| 2.0.0  | 20000000 | 70.5 ns | 16 | 2 |\n\n#### String (small)\n\n| version | requests | /op | B/op | allocs/op |\n|---|---|---|---|---|\n| 1.0.0  | 3000000 | 382 ns | 200 | 3 |\n| 2.0.0  | 20000000 | 89.0 ns | 128 | 2 |\n\n#### String (Large)\n\n| version | requests | /op | B/op | allocs/op |\n|---|---|---|---|---|\n| 1.0.0  | 1000000 | 1056 ns | 776 | 4 |\n| 2.0.0  | 5000000 | 237 ns | 896 | 2 |\n\n#### Time\n\n| version | requests | /op | B/op | allocs/op |\n|---|---|---|---|---|\n| 1.0.0  | 1000000 | 1122 ns | 360 | 5 |\n| 2.0.0  | 3000000 | 401 ns | 48 | 1 |\n\n#### TimestampMS\n\n| version | requests | /op | B/op | allocs/op |\n|---|---|---|---|---|\n| 1.0.0  | 20000000 | 97.9 ns | 32 | 2 |\n| 2.0.0  | 20000000 | 91.2 ns | 32 | 2 |\n\n#### TimestampNano\n\n| version | requests | /op | B/op | allocs/op |\n|---|---|---|---|---|\n| 1.0.0  | 10000000 | 114 ns | 64 | 2 |\n| 2.0.0  | 10000000 | 112 ns | 64 | 2 |\n\n#### Timestamp\n\n| version | requests | /op | B/op | allocs/op |\n|---|---|---|---|---|\n| 1.0.0  | 20000000 | 88.4 ns | 32 | 2 |\n| 2.0.0  | 20000000 | 86.7 ns | 32 | 2 |\n\n#### Uint\n\n| version | requests | /op | B/op | allocs/op |\n|---|---|---|---|---|\n| 1.0.0  | 5000000 | 277 ns | 192 | 3 |\n| 2.0.0  | 20000000 | 64.2 ns | 16 | 2 |\n\n## Licence\n\n[MIT](https://github.com/usk81/generic/blob/master/LICENSE)\n\n## Author\n\n[Yusuke Komatsu](https://github.com/usk81)\n","funding_links":[],"categories":["Go Generate Tools","编辑器插件","Go 生成工具","Libraries for creating HTTP middlewares","Go生成工具","Go 代码生成工具"],"sub_categories":["Routers","代码分析","路由器"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusk81%2Fgeneric","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusk81%2Fgeneric","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusk81%2Fgeneric/lists"}