Documentation
¶
Index ¶
- Constants
- Variables
- func AnyToBool(val any) (bool, bool)
- func AnyToInt(val any) (int64, bool)
- func CastSliceValue(value any, tp reflect.Kind) ([]any, bool)
- func CastValue(value any, tp reflect.Kind) (any, bool)
- func FlattenMap(data map[string]any, prefix string) map[string]any
- func ResolveBytes(r Reader, opts *Options, path string, reader io.Reader) ([]byte, error)
- func ResolvePath(r Reader, opts *Options, path string) string
- func ToSnakeCase(s string) string
- type BaseReader
- type Config
- type EnvReader
- type Field
- type FlagReader
- type JSONReader
- type Options
- type Reader
- type WithConfigCallback
- type WithOptionCallback
Constants ¶
const ReaderEnv = "env"
const ReaderFlag = "flag"
const ReaderJSON = "json"
Variables ¶
var Readers = []string{ ReaderFlag, ReaderJSON, ReaderEnv, }
Full list of default configuration readers available
Functions ¶
func CastSliceValue ¶
cast value to slice of type
func FlattenMap ¶
flatten nest map data to dot separated key data
func ResolveBytes ¶
resolve byte data from file or reader
func ResolvePath ¶
resolve file path for config file
Types ¶
type BaseReader ¶
type BaseReader struct{}
base reader to extend with (optional)
func (BaseReader) ConfigExtension ¶
func (r BaseReader) ConfigExtension() string
file extension for related reader
type Config ¶
type Config struct {
Options *Options
Values map[string]any
// contains filtered or unexported fields
}
Configuration management struct
func Default ¶
func Default(data any, cbs ...WithConfigCallback) (*Config, error)
Default creates instance of configurations using default settings and option to add configs
func DefaultWithOpts ¶
func DefaultWithOpts(data any, ocbs []WithOptionCallback, cbs ...WithConfigCallback) (*Config, error)
DefaultWithOpts creates instance of configurations using default settings with support to add config and options
func New ¶
func New(opts *Options, cbs ...WithConfigCallback) (*Config, error)
Create new instance of configurations with support for setup callbacks
type EnvReader ¶
type EnvReader struct {
BaseReader
}
Configuration Reader for Environment Variables
func NewEnvReader ¶
func NewEnvReader() *EnvReader
func (EnvReader) Configurator ¶
type Field ¶
type Field struct {
Name string
Usage string
Value any
Kind reflect.Kind
Alias []string
List bool
Null bool
}
Field definition struct for loading config
type FlagReader ¶
type FlagReader struct {
BaseReader
// contains filtered or unexported fields
}
Configuration Reader for Flags(Commandline) inputs
func NewFlagReader ¶
func NewFlagReader() *FlagReader
func (*FlagReader) Configurator ¶
func (r *FlagReader) Configurator() string
type JSONReader ¶
type JSONReader struct {
BaseReader
// contains filtered or unexported fields
}
Configuration Reader for JSON Data/File
func NewJSONReaderIO ¶
func NewJSONReaderIO(reader io.Reader) *JSONReader
Create JSON configuration reader using io.Reader
func (*JSONReader) ConfigExtension ¶
func (r *JSONReader) ConfigExtension() string
func (*JSONReader) Configurator ¶
func (r *JSONReader) Configurator() string
type Options ¶
Options struct for configurator
func NewOptions ¶
func NewOptions(cbs ...WithOptionCallback) *Options
Make new options instance using callbacks
type Reader ¶
type Reader interface {
Configurator() string
ConfigExtension() string
Parse(opts *Options, fields []*Field) error
Get(opts *Options, field *Field) (any, bool)
}
configuration reader interface
type WithConfigCallback ¶
Callback type for configuration setup
func Add ¶
func Add(name string, value any, usage string) WithConfigCallback
Callback shortcut to register new field
func Register ¶
func Register(reader Reader) WithConfigCallback
Callback to register new reader instance
type WithOptionCallback ¶
type WithOptionCallback func(*Options)
Callback type for options setup
func UseStrict ¶
func UseStrict(s bool) WithOptionCallback
Set readers to strict mode (experimental)
func WithPriority ¶
func WithPriority(priorities ...string) WithOptionCallback
Set priority of config readers