31 lines
416 B
Go
31 lines
416 B
Go
|
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!
|
||
|
}
|