defaults
defaults copied to clipboard
Initialize structs with default values
It would be fantastic if this library had the option to set a struct field as required. Then when `defaults.Set` is called on a struct with zero value fields that...
## Why To enable stuff like [add support time scalar type](https://github.com/creasty/defaults/pull/12) on users' end. ## What I found this library that does more or less what I envision: https://github.com/mcuadros/go-defaults/blob/master/filler.go
``` package controllers import ( "fmt" "github.com/creasty/defaults" ) func main() { foo := &Parent{} if err := defaults.Set(foo); err != nil { fmt.Println(err) } fmt.Print(foo) } type Child struct {...
`bool` values that are unset (zero value is `false`) or have been set to `false` are indistinguishable from one another. As a result, `bool` values with default `true` that are...
The README shows this example in the Sample struct: ``` ... Working bool `default:"true"` ... ``` When running the tests in the `defaults_test.go` boolean values are not properly being parsed...
Demonstrates the issue in #49 that that a default of `true` will override an existing value of `false` for bool fields.
Hey there! I'd love to be able to set a custom default for a type based on the tag like so: ```go type Duration struct { time.Duration } func (d...
```golang type Thingy struct { Context context.Context } ``` ```golang func (obj *Thingy) SetDefaults() { if defaults.CanUpdate(obj.Context) { // panic obj.Context = context.Background() } } ``` ``` panic: reflect: call...
Hey! I've came across a same issue as [here](https://github.com/creasty/defaults/issues/14). It seems it can be solved by do not passing default tag value to `setField` if current field is a slice.
Example struct ```go type MyStruct struct { BackoffPolicy []time.Duration `default:"...."` } ``` Checked variants: - `default:"{[\"10s\",\"1m\"]}"` - `default:"[\"10s\",\"1m\"]"` - `default:"[10s,1m]"` - `default:"\"10s\",\"1m\""` - `default:"10s,1m"` all of them not works