coreybutler/go-struct-defaults — explained in plain English
Analysis updated 2026-08-04 · repo last pushed 2019-06-21
Set sensible defaults on a large configuration struct with one function call instead of manually initializing every field.
Tag data model fields with default values so new objects always start with predictable, meaningful data.
Use runtime-computed values like timestamps or random numbers as defaults through a custom interface.
Leave specific fields untouched by defaults using an opt-out tag.
| coreybutler/go-struct-defaults | 0xallam/posthog | 0xallam/search-engine | |
|---|---|---|---|
| Stars | 1 | 1 | 1 |
| Language | — | Python | C++ |
| Last pushed | 2019-06-21 | 2026-03-26 | 2023-08-23 |
| Maintenance | Dormant | Maintained | Dormant |
| Setup difficulty | easy | moderate | hard |
| Complexity | 2/5 | 3/5 | 3/5 |
| Audience | developer | pm founder | developer |
Figures from each repo's GitHub metadata at analysis time.
Just add the library to your Go project with go get and start tagging struct fields.
When you create a new data object in Go, every field starts out empty or zero. That's fine for some cases, but often you want sensible starting values, a default name, a default age, a default configuration, without manually setting each one. This library solves that problem by letting you tag your data fields with default values and then automatically filling them in with a single command. You annotate each field with a small tag saying what the default should be, like default:"John Smith" on a name field or default:"27" on an age field. When you call the library's main function on your object, it reads those tags and populates everything for you. It handles simple values like text and numbers, but also more complex ones like lists, key-value maps, and nested objects. You can even use JSON snippets as defaults for complex fields, and it walks through nested structures recursively so defaults deep inside an object still get applied. One particularly useful feature is that it respects values you've already set. If you manually assigned a value to a field before calling the library, it won't overwrite that value with the default. It only fills in fields that are still at their empty starting state. There's also an opt-out tag for fields you want left alone entirely. Who would use this? Anyone building a Go application where objects need predictable starting states. A practical example: you have a configuration struct with thirty fields, most of which should default to sensible values but a few might be overridden by user input. Instead of writing boilerplate code to check and set each field, you tag them and call one function. The library also supports dynamic defaults through a custom interface, meaning if a field needs a value computed at runtime, like a random number or a timestamp, you can define custom logic for that.
A Go library that lets you tag struct fields with default values and automatically fills them in with a single function call, skipping any fields you've already set.
Dormant — no commits in 2+ years (last push 2019-06-21).
No license information was provided in the explanation, so the permissions for using this code are unclear.
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.