Documentation
¶
Index ¶
Examples ¶
Constants ¶
const SupportPackageIsVersion1 = true
SupportPackageIsVersion1 is a compile-time assertion constant. Downstream packages reference this to enforce version compatibility.
Variables ¶
This section is empty.
Functions ¶
func AddToOptions ¶
AddToOptions adds a key-value pair to the Options stored in ctx. If no Options exists in the context, a new one is created. Empty keys are silently ignored and do not allocate.
Example ¶
package main
import (
"context"
"fmt"
"github.com/go-coldbrew/options"
)
func main() {
ctx := context.Background()
// Add request-scoped metadata to context
ctx = options.AddToOptions(ctx, "tenant", "acme-corp")
ctx = options.AddToOptions(ctx, "region", "us-west-2")
// Retrieve values downstream
opts := options.FromContext(ctx)
if tenant, ok := opts.Get("tenant"); ok {
fmt.Println("tenant:", tenant)
}
if region, ok := opts.Get("region"); ok {
fmt.Println("region:", region)
}
}
Output: tenant: acme-corp region: us-west-2
Types ¶
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options are request options passed from ColdBrew to server. Uses RWMutex + map instead of sync.Map since Options is per-request and never shared across goroutines.
func FromContext ¶
FromContext fetches options from provided context. If no options are found, it returns nil.
Example ¶
package main
import (
"context"
"fmt"
"github.com/go-coldbrew/options"
)
func main() {
ctx := context.Background()
// Without any options set, FromContext returns nil
opts := options.FromContext(ctx)
fmt.Println("opts:", opts)
}
Output: opts: <nil>
func (*Options) Delete ¶ added in v0.2.7
Delete is a sync.Map-compatible alias for Del. Only string keys are supported; non-string keys are silently ignored.
func (*Options) Load ¶ added in v0.2.7
Load is a sync.Map-compatible alias for Get. Only string keys are supported; non-string keys return (nil, false).