loader

package module
v0.0.0-...-42df6de Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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)
}

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