loader

package module
v0.0.0-...-6c66404 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List[T any]() []string

List returns the sorted names of all registered implementations for type T.

func LoadConfig

func LoadConfig(bts []byte, cfg any) error

LoadConfig loads a configuration from a byte slice into the given config. The config must be a pointer to a struct. It parses the byteslice as hujson, which allows for C-style comments and trailing commas on arrays and maps. It replaces any environment variables in the JSON string before unmarshalling, properly escaping values to maintain JSON structure. Finally, it unmarshals the JSON into the config struct.

func Register

func Register[T any](name string, factory func() Builder[T])

Register registers a factory method for a type T with the given type name. T is typically an interface that is implmented by the struct of type given by the name.

Types

type Builder

type Builder[T any] interface {
	Configure() (T, error)
}

func Describe

func Describe[T any](name string) (Builder[T], bool)

Describe returns a zero-value Builder for the named type, useful for introspecting config fields (e.g. reflecting on JSON struct tags for help output). Returns nil, false if the name is not registered.

type Helper

type Helper interface {
	Help() string
}

Helper is optionally implemented by Builder types to provide a human-readable description of their configuration. Used by CLI tools to show available config options in help output.

type Loader

type Loader[T any] struct {
	Builder[T]
}

Loader is a struct which can dyanmically unmarshal any type T

func (Loader[T]) Configure

func (l Loader[T]) Configure() (T, error)

func (Loader[T]) MarshalJSON

func (l Loader[T]) MarshalJSON() ([]byte, error)

func (*Loader[T]) UnmarshalJSON

func (b *Loader[T]) UnmarshalJSON(raw []byte) error

type Registry

type Registry[T any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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