Skip to content

Options

Options is the universal input type. Every Core operation that takes parameters takes one. A structured collection of key/value pairs with typed accessors.

type Option struct {
Key string
Value any
}
type Options struct { /* opaque */ }
opts := core.NewOptions(
core.Option{Key: "name", Value: "brain"},
core.Option{Key: "port", Value: 8080},
core.Option{Key: "debug", Value: true},
)
Method What it does
opts.Set(key, v) Add or update a key. Mutates in place.

Each accessor returns the type’s zero value when the key is missing or the stored value isn’t assignable to that type. This is the convenience surface; for strict checks use opts.Get(key) and inspect the Result.

Accessor Returns Zero
opts.String(key) string ""
opts.Int(key) int 0
opts.Bool(key) bool false
opts.Float64(key) float64 0 (promotes int / int64 / float32)
opts.Duration(key) core.Duration 0 (parses string via ParseDuration)
name := opts.String("name")
port := opts.Int("port")
debug := opts.Bool("debug")
weight := opts.Float64("weight")
timeout := opts.Duration("timeout")

For strict reads where missing-vs-typed-zero matters:

r := opts.Get("port")
if !r.OK { return core.Fail(core.NewError("port required")) }
port := r.Value.(int)
Method What it returns
opts.Has(key) true if the key exists, regardless of value type
opts.Len() Number of options
opts.Items() Copy of the underlying option slice — for iteration

options.go — full type definition, accessor implementations, and docstrings with examples.