https://git.jolheiser.com/opt.git
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package opt_test import ( "fmt" "go.jolheiser.com/opt" ) func ExampleApply() { f := Foo{ Bar: "default", } opt.Apply(&f, WithBar("override")) fmt.Println(f.Bar) // Output: // override } func ExampleApplyError() { f := &Foo{ Bar: "default", } err := opt.ApplyError(f, WithBarErr("uh oh!")) // WithBarErr always returns errors.New(b) if err != nil { fmt.Println(err) } // Output: // uh oh! }