{"id":34842292,"url":"https://github.com/serialt/go-defaults","last_synced_at":"2026-05-24T02:36:02.619Z","repository":{"id":133150955,"uuid":"559411155","full_name":"serialt/go-defaults","owner":"serialt","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-30T02:51:52.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-21T06:29:59.750Z","etag":null,"topics":[],"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/serialt.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-30T02:51:44.000Z","updated_at":"2022-10-30T02:51:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"21e139d5-ceed-4613-a215-de43a72d127e","html_url":"https://github.com/serialt/go-defaults","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/serialt/go-defaults","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fgo-defaults","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fgo-defaults/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fgo-defaults/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fgo-defaults/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serialt","download_url":"https://codeload.github.com/serialt/go-defaults/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serialt%2Fgo-defaults/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33419556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T22:14:44.296Z","status":"online","status_checked_at":"2026-05-24T02:00:06.296Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-12-25T17:13:15.323Z","updated_at":"2026-05-24T02:36:02.613Z","avatar_url":"https://github.com/serialt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"go-defaults [![Build Status](https://img.shields.io/github/workflow/status/mcuadros/go-defaults/Test.svg)](https://github.com/mcuadros/go-defaults/actions) [![GoDoc](http://godoc.org/github.com/mcuadros/go-defaults?status.png)](https://pkg.go.dev/github.com/mcuadros/go-defaults) [![GitHub release](https://img.shields.io/github/release/mcuadros/go-defaults.svg)](https://github.com/mcuadros/go-defaults/releases)\n==============================\n\nEnabling stuctures with defaults values using [struct tags](http://golang.org/pkg/reflect/#StructTag).\n\nInstallation\n------------\n\nThe recommended way to install go-defaults\n\n```\ngo get github.com/mcuadros/go-defaults\n```\n\nExamples\n--------\n\nA basic example:\n\n```go\nimport (\n    \"fmt\"\n    \"github.com/mcuadros/go-defaults\"\n    \"time\"\n)\n\ntype ExampleBasic struct {\n    Foo bool   `default:\"true\"` //\u003c-- StructTag with a default key\n    Bar string `default:\"33\"`\n    Qux int8\n    Dur time.Duration `default:\"1m\"`\n}\n\nfunc NewExampleBasic() *ExampleBasic {\n    example := new(ExampleBasic)\n    defaults.SetDefaults(example) //\u003c-- This set the defaults values\n\n    return example\n}\n\n...\n\ntest := NewExampleBasic()\nfmt.Println(test.Foo) //Prints: true\nfmt.Println(test.Bar) //Prints: 33\nfmt.Println(test.Qux) //Prints:\nfmt.Println(test.Dur) //Prints: 1m0s\n```\n\nCaveats\n-------\n\nAt the moment, the way the default filler checks whether it should fill a struct field or not is by comparing the current field value with the corresponding zero value of that type. This has a subtle implication: the zero value set explicitly by you will get overriden by default value during `SetDefaults()` call. So if you need to set the field to container zero value, you need to set it explicitly AFTER setting the defaults.\n\nTake the basic example in the above section and change it slightly:\n```go\n\nexample := ExampleBasic{\n    Bar: 0,\n}\ndefaults.SetDefaults(example)\nfmt.Println(example.Bar) //Prints: 33 instead of 0 (which is zero value for int)\n\nexample.Bar = 0 // set needed zero value AFTER applying defaults\nfmt.Println(example.Bar) //Prints: 0\n\n```\n\nLicense\n-------\n\nMIT, see [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserialt%2Fgo-defaults","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserialt%2Fgo-defaults","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserialt%2Fgo-defaults/lists"}