Documentation
¶
Overview ¶
Example ¶
args := []string{"--hello", "world"}
// Create a target for cross-platform abstractions
target := cross.NewTest(platform.Linux, arch.AMD64)
filesystem := target.FS()
// Use environment provider from target and set environment variable
osEnv := target.Env()
osEnv.Set("env", "yes")
builder := config.NewBuilder(
config.NewYaml(filesystem, "config.yml"),
config.NewJson(filesystem, "config.json"),
config.NewToml(filesystem, "config.toml"),
config.NewEnv(osEnv, config.EnvOption{Prefix: "env"}),
config.NewDotEnv(filesystem, ".env"),
config.NewFlag([]config.Flag{
&config.StringFlag{
Name: "hello",
},
}, args),
)
root, err := builder.Build()
if err != nil {
log.Fatal(err)
}
cfg, err := root.Get(&config.GetContext{})
if err != nil {
log.Fatal(err)
} else {
log.Printf("%v", cfg)
}
Index ¶
- Constants
- func Merge(from any, to any) (any, error)
- type Builder
- type Change
- type ChangeType
- type Codec
- type EnvOption
- type EnvProvider
- type Factory
- func NewDotEnv(filesystem fs.FS, file string, options ...FileOption) Factory
- func NewEnv(environment env.Environment, options ...EnvOption) Factory
- func NewFactory(providers ...Provider) Factory
- func NewFile(filesystem fs.FS, file string, codec Codec, options ...FileOption) Factory
- func NewFlag(flags []Flag, args []string, options ...FlagOption) Factory
- func NewGlob(filesystem fs.FS, filePath filepath.Provider, resolver GlobResolver, ...) Factory
- func NewGlobUp(filesystem fs.FS, filePath filepath.Provider, resolver GlobResolver, ...) Factory
- func NewJson(filesystem fs.FS, file string, options ...FileOption) Factory
- func NewToml(filesystem fs.FS, file string, options ...FileOption) Factory
- func NewYaml(filesystem fs.FS, file string, options ...FileOption) Factory
- type FileBeforeGet
- type FileOption
- type Flag
- type FlagOption
- type GetContext
- type GlobOption
- type GlobResolver
- type JsonOption
- type Marshaler
- type Provider
- type Root
- type SetContext
- type StringFlag
- type StringSliceFlag
- type Transformer
- type Unmarshaler
Examples ¶
Constants ¶
View Source
const ( Create changeType = "create" Update changeType = "update" Delete changeType = "delete" )
Variables ¶
This section is empty.
Functions ¶
func Merge ¶ added in v0.1.2
Merge merges 'from' into 'to' returning a new value without mutating inputs. Semantics (retains original intention): - Primitive / non-composite conflicts: keep 'to' value - Map conflicts: recursively merge; on leaf conflict keep 'to' - Slice/array conflicts: concatenate (from... + to...) if same concrete type - Nil handling: if one side is nil, return the other (deep copied for composites)
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func NewBuilder ¶
func (*Builder) WithFactory ¶ added in v0.6.0
func (*Builder) WithProvider ¶ added in v0.6.0
type Change ¶ added in v0.1.2
type Change struct {
ChangeType ChangeType
Path []string
From any
To any
}
type ChangeType ¶ added in v0.1.2
type ChangeType interface {
// contains filtered or unexported methods
}
type Codec ¶ added in v0.1.3
type Codec interface {
Marshaler
Unmarshaler
}
func NewJsonCodec ¶ added in v0.1.3
func NewJsonCodec() Codec
func NewTomlCodec ¶ added in v0.1.3
func NewTomlCodec() Codec
func NewYamlCodec ¶ added in v0.1.3
func NewYamlCodec() Codec
type EnvOption ¶ added in v0.1.4
type EnvOption struct {
Prefix string
Transformers []Transformer
}
type EnvProvider ¶
type EnvProvider struct {
// contains filtered or unexported fields
}
func (*EnvProvider) Get ¶
func (p *EnvProvider) Get(ctx *GetContext) (any, error)
type Factory ¶ added in v0.6.0
func NewDotEnv ¶ added in v0.1.1
func NewDotEnv(filesystem fs.FS, file string, options ...FileOption) Factory
func NewFactory ¶ added in v0.6.0
func NewGlob ¶
func NewGlob( filesystem fs.FS, filePath filepath.Provider, resolver GlobResolver, directory string, pattern string, options ...GlobOption) Factory
type FileBeforeGet ¶ added in v0.1.4
type FileBeforeGet func(ctx *GetContext, provider Provider, file string) (any, error)
type FileOption ¶ added in v0.1.4
type FileOption struct {
Transformers []Transformer
BeforeGet FileBeforeGet
}
type FlagOption ¶ added in v0.1.6
type FlagOption struct {
Transformers []Transformer
}
type GetContext ¶ added in v0.1.3
type GetContext struct {
MergedConfiguration any
}
type GlobOption ¶ added in v0.1.4
type GlobOption struct {
Transformers []Transformer
}
type GlobResolver ¶ added in v0.6.0
GlobResolver returns the Provider for the given glob match
func DefaultGlobResolver ¶ added in v0.6.0
func DefaultGlobResolver(fileSystem fs.FS, path filepath.Provider) GlobResolver
type JsonOption ¶ added in v0.1.4
type JsonOption struct {
Transformers []Transformer
}
type Provider ¶
type Provider interface {
Get(ctx *GetContext) (any, error)
}
func NewMemory ¶ added in v0.1.3
func NewMemory(memory any, transformers ...Transformer) Provider
type SetContext ¶ added in v0.1.3
type SetContext struct{}
type StringFlag ¶
type StringFlag struct {
Name string
Default string
Usage string
// contains filtered or unexported fields
}
func (*StringFlag) Set ¶
func (s *StringFlag) Set(value string) error
func (*StringFlag) String ¶
func (s *StringFlag) String() string
func (*StringFlag) Value ¶
func (s *StringFlag) Value() any
type StringSliceFlag ¶
type StringSliceFlag struct {
Name string
Default []string
Usage string
// contains filtered or unexported fields
}
func (*StringSliceFlag) Set ¶
func (s *StringSliceFlag) Set(value string) error
func (*StringSliceFlag) String ¶
func (s *StringSliceFlag) String() string
func (*StringSliceFlag) Value ¶
func (s *StringSliceFlag) Value() any
type Transformer ¶ added in v0.1.3
func FuncTransformer ¶ added in v0.1.3
func FuncTransformer(transform func(any) (any, error)) Transformer
func FuncTypedTransformer ¶ added in v0.1.7
func FuncTypedTransformer[T any](transform func(T) (T, error)) Transformer
type Unmarshaler ¶ added in v0.1.3
Click to show internal directories.
Click to hide internal directories.