configutils

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DELIM string = "."

Functions

func ApplyTransforms

func ApplyTransforms(flat map[string]any, targets map[string]TransformTarget, options TransformOptions) map[string]any

func BuildTransformMap

func BuildTransformMap(id string, schema any) map[string]TransformTarget

Build transform map

func Flatten

func Flatten(prefix string, v any, out map[string]any)

Flatten `data: { key: value }` into `data.key: value“

func Unflatten

func Unflatten(flat map[string]any) map[string]any

Unflatten `data.key: value` into `data: { key: value }`

Types

type Config

type Config struct {
	Layer      *koanf.Koanf
	ReloadFunc func(string)
}

func New

func New() *Config

Create a New Config

func NewWith

func NewWith(delim string, reloadFunc func(string)) *Config

Create a New Config with Args

func (Config) ApplyTransformFuncs

func (config Config) ApplyTransformFuncs(id string, schema any, path string, options TransformOptions)

Apply Transform funcs based on `transform`, `childtransform` and `aliases` in struct schema

func (*Config) Load

func (config *Config) Load(data any, path string) error

Load data into Config path

func (*Config) LoadDir

func (config *Config) LoadDir(path string, dir string, ext string, parser koanf.Parser, transform func(*Config, string)) error

Load files inside of dir with parser into Config path (default: ext="")

func (*Config) LoadEnv

func (config *Config) LoadEnv(transformFunc func(key string, value string) (string, any)) (*env.Env, error)

Load environment into Config with transformFunc

func (*Config) LoadFile

func (config *Config) LoadFile(path string, parser koanf.Parser) (*file.File, error)

Load file with parser into Config

func (*Config) MergeLayers

func (config *Config) MergeLayers(layers ...*koanf.Koanf) error

Merge layers into Config

func (*Config) OnReload

func (config *Config) OnReload(reloadFunc func(string))

Set ReloadFunc

func (*Config) TemplateConfig

func (config *Config) TemplateConfig() error

Template Config with environment variables

func (*Config) WatchFile

func (config *Config) WatchFile(fileProvider *file.File, path string)

Watch file with file provider

type TransformOptions added in v0.0.3

type TransformOptions struct {
	Transforms map[string]func(key string, value any) (string, any)
	OnUse      map[string]func(source string, target TransformTarget)
}

type TransformTarget

type TransformTarget struct {
	OutputKey      string
	Parent         string
	Source         reflect.StructField
	OnUse          string
	Transform      string
	ChildTransform string
	Value          any
}

Jump to

Keyboard shortcuts

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