util

package
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOptions

func ApplyOptions[T any](target *T, opts ...Option[T])

ApplyOptions applies a list of options to the target configuration.

Types

type FunctionalOption

type FunctionalOption[T any] func(*T)

FunctionalOption wraps a function to implement the Option interface. This allows simple functions to be used as options without defining custom types.

Example:

func WithValue(val int) util.Option[MyConfig] {
    return util.FunctionalOption[MyConfig](func(cfg *MyConfig) {
        cfg.Value = val
    })
}

func (FunctionalOption[T]) ApplyTo

func (f FunctionalOption[T]) ApplyTo(target *T)

ApplyTo implements the Option interface for FunctionalOption.

type Option

type Option[T any] interface {
	ApplyTo(target *T)
}

Option is a generic interface for applying configuration to a target. This provides a type-safe way to build functional options for any configuration type.

Example:

type MyConfig struct {
    Name string
    Value int
}

type MyOption = util.Option[MyConfig]

func WithName(name string) MyOption {
    return util.FunctionalOption[MyConfig](func(cfg *MyConfig) {
        cfg.Name = name
    })
}

Directories

Path Synopsis
olm
test

Jump to

Keyboard shortcuts

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