Documentation
¶
Index ¶
- Constants
- Variables
- func Define[T any](config *Config, key string, defaultValue T, options ...MetadataOption) error
- func DefineConfigFile(config *Config, key string, defaultValue []string, options ...MetadataOption) error
- func DefineVar[T any](config *Config, key string, boundVariable *T, options ...MetadataOption) error
- func GenerateEnvName(key string) string
- func GenerateFlagName(key string) string
- func Get[T any](config *Config, key string) (T, error)
- func ReadEnv(c *Config) error
- func ReadForm(c *Config, form url.Values) error
- type Config
- func (config *Config) Accept(key string) bool
- func (config *Config) Entries() <-chan EntryInterface
- func (config *Config) GetEntry(key string) (EntryInterface, bool)
- func (config *Config) Ignoring(keys ...string) *Config
- func (config *Config) Only(keys ...string) *Config
- func (config *Config) Sort()
- func (config *Config) SortFunc(fun func([]string) []string)
- func (config *Config) ToFlags(useShort bool) []string
- type ConfigFilter
- type ConvertCallback
- type Converter
- type Entry
- func (e *Entry[T]) Convert(frontend Frontend, args ...any) error
- func (e *Entry[T]) Get() interface{}
- func (e *Entry[T]) GetKey() string
- func (e *Entry[T]) GetMetadata() *EntryMetadata
- func (e *Entry[T]) GetValue() interface{}
- func (e *Entry[T]) IsBoolFlag() bool
- func (e *Entry[T]) Set(value string) error
- func (e *Entry[T]) String() string
- func (e *Entry[T]) Type() string
- type EntryInterface
- type EntryMetadata
- type Frontend
- type MetadataOption
- func WithDescription(description string) MetadataOption
- func WithEnvName(name string) MetadataOption
- func WithFlagName(name string) MetadataOption
- func WithFormat(format string) MetadataOption
- func WithShortFlagName(name string) MetadataOption
- func WithSliceSeparator(sep rune) MetadataOption
- func WithoutEnv() MetadataOption
- func WithoutFlagName() MetadataOption
Constants ¶
const DEFAULT_NESTING_SEPARATOR = "."
Variables ¶
var BoolConverter = newConverter(boolFromString)
var BytesConverter = newConverter(bytesFromString)
var Float32Converter = newConverter(float32FromString)
var Float64Converter = newConverter(float64FromString)
var IPConverter = newConverter(ipFromString)
var Int16Converter = newConverter(int16FromString)
var Int32Converter = newConverter(int32FromString)
var Int64Converter = newConverter(int64FromString)
var Int8Converter = newConverter(int8FromString)
var IntConverter = newConverter(intFromString)
var StringConverter = newConverter( func(entry *Entry[string], stringValue string) error { *entry.ValueP = stringValue entry.Value = stringValue return nil }, )
var StringSliceConverter = newConverter(stringSliceFromString)
var Uint16Converter = newConverter(uint16FromString)
var Uint32Converter = newConverter(uint32FromString)
var Uint64Converter = newConverter(uint64FromString)
var Uint8Converter = newConverter(uint8FromString)
var UintConverter = newConverter(uintFromString)
Functions ¶
func Define ¶
func Define[T any](config *Config, key string, defaultValue T, options ...MetadataOption) error
Define lets the config object store the Value
func DefineConfigFile ¶
func DefineConfigFile(config *Config, key string, defaultValue []string, options ...MetadataOption) error
func DefineVar ¶
func DefineVar[T any](config *Config, key string, boundVariable *T, options ...MetadataOption) error
DefineVar lets the user store the Value
func GenerateEnvName ¶
func GenerateFlagName ¶
Types ¶
type Config ¶
type Config struct {
NestingSeparator string
// contains filtered or unexported fields
}
Config is a structure that plays the role of a namespace if you need to manage several configurations
func (*Config) Entries ¶
func (config *Config) Entries() <-chan EntryInterface
Entries iterates over the entries of the config, applying the filters This is the single way to access the entrie of the config
func (*Config) Sort ¶
func (config *Config) Sort()
Sort sorts the entries of the config by their keys in alphabetical order
func (*Config) SortFunc ¶
SortFunc allows to sort the entries of the config using a custom function The function should take a slice of strings (the keys) and return a sorted slice of strings even if it is sorted in-place. This function can be run after a previous sort
type ConfigFilter ¶
type ConvertCallback ¶
func ConvertCallbackFactory1 ¶
func ConvertCallbackFactory1[T any, A any](fun func(entry *Entry[T], arg A) error) ConvertCallback[T]
ConvertCallbackFactory1 is a function that turns a specific 1-argument function into a generic ConvertCallback
func ConvertCallbackFactory2 ¶
func ConvertCallbackFactory2[T any, A any, B any](fun func(entry *Entry[T], arg0 A, arg1 B) error) ConvertCallback[T]
ConvertCallbackFactory2 is a function that turns a specific 2-argument function into a generic ConvertCallback
type Converter ¶
type Converter[T any] interface { Register(name Frontend, callback ConvertCallback[T]) error Convert(frontend Frontend, entry *Entry[T], args ...any) error }
A Converter is an object attached to a type. It may supports several frontends that are able to convert the entry to their own language
type Entry ¶
type Entry[T any] struct { Metadata *EntryMetadata Key string ValueP *T // to bind the Value if not stored by the entry Value T // contains filtered or unexported fields }
Entry is a structure that represents an item in the configuration
func (*Entry[T]) Convert ¶
Convert converts the entry value using the provided frontend and arguments. It updates the value of the entry.
func (*Entry[T]) Get ¶
func (e *Entry[T]) Get() interface{}
Method to be compatible with urfave/cli.Value interface
func (*Entry[T]) GetMetadata ¶
func (e *Entry[T]) GetMetadata() *EntryMetadata
GetMetadata returns the metadata of the entry
func (*Entry[T]) GetValue ¶
func (e *Entry[T]) GetValue() interface{}
GetValue returns the value of the entry as an interface{}.
func (*Entry[T]) IsBoolFlag ¶
For flag package compatibility see https://pkg.go.dev/flag#Value
func (*Entry[T]) Set ¶
Method to be compatible with flag.Value interface (and spf13/pflag.Value interface)
type EntryInterface ¶
type EntryInterface interface {
GetKey() string
GetValue() interface{}
GetMetadata() *EntryMetadata
Set(string) error
String() string
Convert(frontend Frontend, args ...any) error
}
EntryInterface is the object that unifies all the provided entries (that have different types)
type EntryMetadata ¶
type MetadataOption ¶
type MetadataOption = func(*EntryMetadata)
func WithDescription ¶
func WithDescription(description string) MetadataOption
func WithEnvName ¶
func WithEnvName(name string) MetadataOption
func WithFlagName ¶
func WithFlagName(name string) MetadataOption
func WithFormat ¶
func WithFormat(format string) MetadataOption
func WithShortFlagName ¶
func WithShortFlagName(name string) MetadataOption
func WithSliceSeparator ¶
func WithSliceSeparator(sep rune) MetadataOption
func WithoutEnv ¶
func WithoutEnv() MetadataOption
func WithoutFlagName ¶
func WithoutFlagName() MetadataOption