{"id":20610528,"url":"https://github.com/reugn/go-traits","last_synced_at":"2026-03-03T20:31:40.827Z","repository":{"id":54494319,"uuid":"195113002","full_name":"reugn/go-traits","owner":"reugn","description":"A concept package that helps implement mixin behavior using embedded structs and hook interfaces.","archived":false,"fork":false,"pushed_at":"2022-02-22T09:37:52.000Z","size":19,"stargazers_count":25,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-26T01:33:50.621Z","etag":null,"topics":["boilerplate","capabilities","composition","go","mixin","mixins","struct","trait","traits"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/reugn/go-traits","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/reugn.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":"2019-07-03T19:10:32.000Z","updated_at":"2025-06-04T12:40:04.000Z","dependencies_parsed_at":"2022-08-13T17:40:49.925Z","dependency_job_id":null,"html_url":"https://github.com/reugn/go-traits","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/reugn/go-traits","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reugn%2Fgo-traits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reugn%2Fgo-traits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reugn%2Fgo-traits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reugn%2Fgo-traits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reugn","download_url":"https://codeload.github.com/reugn/go-traits/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reugn%2Fgo-traits/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30058275,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["boilerplate","capabilities","composition","go","mixin","mixins","struct","trait","traits"],"created_at":"2024-11-16T10:17:06.607Z","updated_at":"2026-03-03T20:31:40.786Z","avatar_url":"https://github.com/reugn.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-traits\n![Test](https://github.com/reugn/go-traits/workflows/Test/badge.svg)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/reugn/go-traits)](https://pkg.go.dev/github.com/reugn/go-traits)\n[![Go Report Card](https://goreportcard.com/badge/github.com/reugn/go-traits)](https://goreportcard.com/report/github.com/reugn/go-traits)\n\n`go-traits` is a concept package that helps implement [mixin](https://en.wikipedia.org/wiki/Mixin) behavior using embedded structs and hook interfaces.\n\n**Trait list:**  \n* `traits.Hasher` - An extension for unique hash generators.\n* `traits.Converter` - An extension for miscellaneous converters.\n* `traits.Stringer` - `fmt.Stringer` implementation extension.\n* `traits.Validator` - Struct fields validation extension.\n* `traits.Default` - Struct fields initialization extension.\n\n**Marker trait list:**\n* `traits.PreventUnkeyed` - A struct to embed when you need to forbid unkeyed literals usage.\n* `traits.NonComparable` - A struct to embed when you need to prevent structs comparison.\n\n**Hook interfaces:**  \n* `traits.bootstrap` - the `Bootstrap` function will be triggered on `traits.Init` call.\n* `traits.schedule` - implement `traits.schedule` to schedule a function in a separate goroutine on `traits.Init` call.\n* `traits.finalize` - the `Finalize` function will be set as an object finalizer via `runtime.SetFinalizer` on `traits.Init` call.\n\n## Examples\n```go\ntype inner struct {\n\tArr []bool\n}\n\ntype test struct {\n\ttraits.Hasher\n\ttraits.Converter\n\ttraits.Stringer\n\ttraits.Validator\n\n\tNum   int    `json:\"num\"`\n\tStr   string `json:\"str\" valid:\"numeric\"`\n\tInn   *inner\n\tpstr  *string\n\tC     chan interface{} `json:\"-\"`\n\tIface interface{}\n}\n\nfunc (t *test) Bootstrap() {\n\tfmt.Println(\"Bootstrap Test struct...\")\n}\n\nfunc (t *test) Finalize() {\n\tfmt.Println(\"Finalize Test struct...\")\n}\n\nfunc main() {\n\tstr := \"bar\"\n\tobj := test{\n\t\tNum:   1,\n\t\tStr:   \"abc\",\n\t\tInn:   \u0026inner{make([]bool, 2)},\n\t\tpstr:  \u0026str,\n\t\tC:     make(chan interface{}),\n\t\tIface: \"foo\",\n\t}\n\ttraits.Init(\u0026obj)\n\n\tfmt.Println(obj.String())\n\tfmt.Println(obj.ToJSON())\n\tfmt.Println(obj.Md5Hex())\n\tfmt.Println(obj.Sha256Hex())\n\tfmt.Println(obj.HashCode32())\n\tfmt.Println(obj.Validate())\n}\n```\nSee the examples folder for more.\n\n## Contributing\nAny proposal or improvement is very welcome.\n\n## License\nLicensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freugn%2Fgo-traits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freugn%2Fgo-traits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freugn%2Fgo-traits/lists"}