Analysis updated 2026-07-13 · repo last pushed 2019-09-17
Set default values for configuration structs without writing repetitive setup code.
Default user preference toggles to 'on' when building apps that accept user settings.
Pre-fill standard starting values for request objects and data models automatically.
| yywing/go-defaults | aasheeshlikepanner/vase | alexzielenski/controller-runtime | |
|---|---|---|---|
| Stars | — | 0 | — |
| Language | Go | Go | Go |
| Last pushed | 2019-09-17 | — | 2022-04-20 |
| Maintenance | Dormant | — | Dormant |
| Setup difficulty | easy | moderate | hard |
| Complexity | 2/5 | 4/5 | 4/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
Just run go get to add the library to your Go project and call SetDefaults on your structs.
Go-defaults is a small helper library for the Go programming language that lets developers specify default values for data fields using simple annotations. Instead of writing repetitive code to manually set default values every time you create a new data structure, you just tag a field with default:"true" or default:"33", and the library handles filling in those values for you automatically. At a high level, when you call the library's SetDefaults function on a data structure, it looks at each field to see if you left a "default" instruction on it. If it finds one, it applies that value to the field. For example, if you have a field meant to hold a time duration and tag it with a default of "1m," the library will automatically set it to one minute. If a field doesn't have a default tag, it just gets left alone. Developers working in Go would use this when they have configuration settings, data models, or request objects where many fields typically have standard starting values. For instance, if you are building an app that accepts user preferences, you might want certain toggles to default to "on" unless the user specifically turns them off. This tool saves a developer from writing boilerplate setup code over and over. There is one notable tradeoff to be aware of. The library decides whether to fill in a default by checking if a field is currently empty. In Go, "empty" means the zero value for that type, like 0 for numbers or false for toggles. This means if you intentionally set a number field to 0 before applying defaults, the library will see that 0 as "empty" and overwrite it with your specified default. To get around this, developers need to apply their defaults first, and only then manually set any fields that genuinely need to be zero.
A small Go library that automatically fills in default values for data fields using simple tags, so you don't have to write repetitive setup code for every new data structure.
Mainly Go. The stack also includes Go.
Dormant — no commits in 2+ years (last push 2019-09-17).
Setup difficulty is rated easy, with roughly 5min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.