This repository has been archived on 2022-03-03. You can view files and clone it, but cannot push or open issues/pull-requests.
opt/opt_example_test.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!
}