Documentation
¶
Overview ¶
Example ¶
package main import ( "context" "fmt" "github.com/adverax/configs" "github.com/adverax/fetchers/maps/maps" "time" ) type MyConfig struct { BaseConfig Name String `config:"name"` Interval Integer `config:"interval"` StartAt Time `config:"start_at"` } func DefaultConfig() *MyConfig { return &MyConfig{ Name: NewString("unknown"), } } func main() { // This example demonstrates how to use dynamic loading configs. // // First, create source: source := maps.Engine{ "name": "My App", "interval": int64(10), "start_at": time.Now().Format(time.RFC3339), } // Then create loader: loader, err := configs.NewBuilder(). WithSource(source). WithDistinct(true). Build() if err != nil { panic(err) } // Then load initial configuration: config := DefaultConfig() Init(config) err = loader.Load(config) if err != nil { panic(err) } // Then create watcher: watcher, err := NewWatcherBuilder(). WithConfig(config). WithLoader(loader). WithInterval(10 * time.Second). WithNewConfig(func() Config { return DefaultConfig() }). Build() if err != nil { panic(err) } // Start watcher: watcher.Start() defer watcher.Close() // Now you can use dynamic config. usingConfig(context.Background(), config) } func usingConfig(ctx context.Context, config *MyConfig) { // For example, print it: name, _ := config.Name.Get(ctx) interval, _ := config.Interval.Get(ctx) fmt.Println(name, interval) }
Output: My App 10
Index ¶
- Variables
- func Assign(dst, src Config)
- type BaseConfig
- type Boolean
- type BooleanField
- func (that *BooleanField) Fetch(_ context.Context) (bool, error)
- func (that *BooleanField) Get(ctx context.Context) (bool, error)
- func (that *BooleanField) Init(c Config)
- func (that *BooleanField) Let(_ context.Context, value bool) error
- func (that *BooleanField) Set(ctx context.Context, value bool) error
- func (that *BooleanField) String() string
- type BooleanTypeHandler
- type Clonable
- type Config
- type Duration
- type DurationField
- func (that *DurationField) Fetch(ctx context.Context) (time.Duration, error)
- func (that *DurationField) Get(ctx context.Context) (time.Duration, error)
- func (that *DurationField) Init(c Config)
- func (that *DurationField) Let(ctx context.Context, value time.Duration) error
- func (that *DurationField) Set(ctx context.Context, value time.Duration) error
- func (that *DurationField) String() string
- type DurationTypeHandler
- type Float
- type FloatField
- func (that *FloatField) Fetch(ctx context.Context) (float64, error)
- func (that *FloatField) Get(ctx context.Context) (float64, error)
- func (that *FloatField) Init(c Config)
- func (that *FloatField) Let(ctx context.Context, value float64) error
- func (that *FloatField) Set(ctx context.Context, value float64) error
- func (that *FloatField) String() string
- type FloatTypeHandler
- type Integer
- type IntegerField
- func (that *IntegerField) Fetch(ctx context.Context) (int64, error)
- func (that *IntegerField) Get(ctx context.Context) (int64, error)
- func (that *IntegerField) Init(c Config)
- func (that *IntegerField) Let(ctx context.Context, value int64) error
- func (that *IntegerField) Set(ctx context.Context, value int64) error
- func (that *IntegerField) String() string
- type IntegerTypeHandler
- type Loader
- type Logger
- type String
- type StringField
- func (that *StringField) Fetch(ctx context.Context) (string, error)
- func (that *StringField) Get(ctx context.Context) (string, error)
- func (that *StringField) Init(c Config)
- func (that *StringField) Let(ctx context.Context, value string) error
- func (that *StringField) Set(ctx context.Context, value string) error
- func (that *StringField) String() string
- type StringTypeHandler
- type Strings
- type StringsField
- func (that *StringsField) Fetch(ctx context.Context) ([]string, error)
- func (that *StringsField) Get(ctx context.Context) ([]string, error)
- func (that *StringsField) Init(c Config)
- func (that *StringsField) Let(ctx context.Context, value []string) error
- func (that *StringsField) Set(ctx context.Context, value []string) error
- func (that *StringsField) String() string
- type StringsTypeHandler
- type Time
- type TimeField
- func (that *TimeField) Fetch(ctx context.Context) (time.Time, error)
- func (that *TimeField) Get(ctx context.Context) (time.Time, error)
- func (that *TimeField) Import(ctx context.Context, value interface{}) error
- func (that *TimeField) Init(c Config)
- func (that *TimeField) Let(ctx context.Context, value time.Time) error
- func (that *TimeField) Set(ctx context.Context, value time.Time) error
- func (that *TimeField) String() string
- type TimeTypeHandler
- type TypeHandler
- type Watcher
- type WatcherBuilder
- func (that *WatcherBuilder) Build() (*Watcher, error)
- func (that *WatcherBuilder) WithConfig(config Config) *WatcherBuilder
- func (that *WatcherBuilder) WithInterval(interval time.Duration) *WatcherBuilder
- func (that *WatcherBuilder) WithLoader(loader Loader) *WatcherBuilder
- func (that *WatcherBuilder) WithLogger(logger Logger) *WatcherBuilder
- func (that *WatcherBuilder) WithNewConfig(newConfig func() Config) *WatcherBuilder
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrRequiredFieldNewConfig = errors.New("newConfig is required") ErrRequiredFieldLoader = errors.New("loader is required") ErrRequiredFieldConfig = errors.New("config is required") )
View Source
var TimeFormat = time.RFC3339
Functions ¶
Types ¶
type BaseConfig ¶
type BooleanField ¶
func NewBoolean ¶
func NewBoolean(value bool) *BooleanField
func (*BooleanField) Init ¶
func (that *BooleanField) Init(c Config)
func (*BooleanField) String ¶
func (that *BooleanField) String() string
type BooleanTypeHandler ¶
type BooleanTypeHandler struct {
configs.BooleanTypeHandler
}
func (*BooleanTypeHandler) New ¶
func (that *BooleanTypeHandler) New(conf Config) interface{}
type DurationField ¶
func NewDuration ¶
func NewDuration(value time.Duration) *DurationField
func (*DurationField) Init ¶
func (that *DurationField) Init(c Config)
func (*DurationField) String ¶
func (that *DurationField) String() string
type DurationTypeHandler ¶
type DurationTypeHandler struct {
configs.DurationTypeHandler
}
func (*DurationTypeHandler) New ¶
func (that *DurationTypeHandler) New(conf Config) interface{}
type FloatField ¶
func NewFloat ¶
func NewFloat(value float64) *FloatField
func (*FloatField) Init ¶
func (that *FloatField) Init(c Config)
func (*FloatField) String ¶
func (that *FloatField) String() string
type FloatTypeHandler ¶
type FloatTypeHandler struct {
configs.FloatTypeHandler
}
func (*FloatTypeHandler) New ¶
func (that *FloatTypeHandler) New(conf Config) interface{}
type IntegerField ¶
func NewInteger ¶
func NewInteger(value int64) *IntegerField
func (*IntegerField) Init ¶
func (that *IntegerField) Init(c Config)
func (*IntegerField) String ¶
func (that *IntegerField) String() string
type IntegerTypeHandler ¶
type IntegerTypeHandler struct {
configs.IntegerTypeHandler
}
func (*IntegerTypeHandler) New ¶
func (that *IntegerTypeHandler) New(conf Config) interface{}
type StringField ¶
func NewString ¶
func NewString(value string) *StringField
func (*StringField) Init ¶
func (that *StringField) Init(c Config)
func (*StringField) String ¶
func (that *StringField) String() string
type StringTypeHandler ¶
type StringTypeHandler struct {
configs.StringTypeHandler
}
func (*StringTypeHandler) New ¶
func (that *StringTypeHandler) New(conf Config) interface{}
type StringsField ¶
func NewStrings ¶
func NewStrings(value []string) *StringsField
func (*StringsField) Init ¶
func (that *StringsField) Init(c Config)
func (*StringsField) String ¶
func (that *StringsField) String() string
type StringsTypeHandler ¶
type StringsTypeHandler struct {
configs.StringsTypeHandler
}
func (*StringsTypeHandler) New ¶
func (that *StringsTypeHandler) New(conf Config) interface{}
type TimeTypeHandler ¶
type TimeTypeHandler struct {
configs.TimeTypeHandler
}
func (*TimeTypeHandler) New ¶
func (that *TimeTypeHandler) New(conf Config) interface{}
type TypeHandler ¶
type TypeHandler interface { configs.TypeHandler New(conf Config) interface{} }
type WatcherBuilder ¶
type WatcherBuilder struct {
// contains filtered or unexported fields
}
func NewWatcherBuilder ¶
func NewWatcherBuilder() *WatcherBuilder
func (*WatcherBuilder) Build ¶
func (that *WatcherBuilder) Build() (*Watcher, error)
func (*WatcherBuilder) WithConfig ¶
func (that *WatcherBuilder) WithConfig(config Config) *WatcherBuilder
func (*WatcherBuilder) WithInterval ¶
func (that *WatcherBuilder) WithInterval(interval time.Duration) *WatcherBuilder
func (*WatcherBuilder) WithLoader ¶
func (that *WatcherBuilder) WithLoader(loader Loader) *WatcherBuilder
func (*WatcherBuilder) WithLogger ¶
func (that *WatcherBuilder) WithLogger(logger Logger) *WatcherBuilder
func (*WatcherBuilder) WithNewConfig ¶
func (that *WatcherBuilder) WithNewConfig(newConfig func() Config) *WatcherBuilder
Click to show internal directories.
Click to hide internal directories.