options

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 0 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply[T any](cfg *T, opts ...Option[T])

Apply applies functional options to a config struct.

Example:

cfg := &Config{}
options.Apply(cfg, WithHost("localhost"))

Types

type Builder

type Builder[T any] struct {
	// contains filtered or unexported fields
}

Builder provides a fluent interface for building config with options.

Example:

cfg := options.NewBuilder(defaultCfg).
	With(WithHost("localhost")).
	Build()

func NewBuilder

func NewBuilder[T any](defaults T) *Builder[T]

NewBuilder creates a new options builder with default config.

func (*Builder[T]) Build

func (b *Builder[T]) Build() T

Build applies all options and returns the final config.

func (*Builder[T]) Ptr

func (b *Builder[T]) Ptr() *T

Ptr returns a pointer to the built config.

func (*Builder[T]) With

func (b *Builder[T]) With(opt Option[T]) *Builder[T]

With adds an option to the builder.

Returns:

The builder instance for chaining.

type Option added in v0.2.1

type Option[T any] func(*T)

Option is a functional option for configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL