Documentation
¶
Index ¶
- Constants
- Variables
- func Clone(from, to context.Context) (context.Context, error)
- func GetBool(ctx context.Context, path string, d ...bool) (bool, error)
- func GetBoolIfExists(ctx context.Context, path string) (bool, bool, error)
- func GetDuration(ctx context.Context, path string, d ...time.Duration) (time.Duration, error)
- func GetDurationIfExists(ctx context.Context, path string) (time.Duration, bool, error)
- func GetInt(ctx context.Context, path string, d ...int64) (int64, error)
- func GetIntIfExists(ctx context.Context, path string) (int64, bool, error)
- func GetModule(ctx context.Context, name string) (onlineconfInterface.Module, error)
- func GetOrAddModule(ctx context.Context, name string) (onlineconfInterface.Module, error)
- func GetString(ctx context.Context, path string, d ...string) (string, error)
- func GetStringIfExists(ctx context.Context, path string) (string, bool, error)
- func GetStrings(ctx context.Context, path string, defaultValue []string) ([]string, error)
- func GetStruct(ctx context.Context, path string, value interface{}) (bool, error)
- func Initialize(ctx context.Context, options ...onlineconfInterface.Option) (context.Context, error)
- func MakePath(s ...string) string
- func RegisterSubscription(ctx context.Context, module string, params []string, callback func() error) error
- func Release(main, cloned context.Context) error
- func StartWatcher(ctx context.Context) error
- func StopWatcher(ctx context.Context) error
- func ToContext(ctx context.Context, oi onlineconfInterface.Instance) context.Context
- func WithConfigDir(path string) options
- func WithLogger(logger onlineconfInterface.Logger) options
- func WithModules(moduleNames []string, required bool) options
- type DefaultLogger
- type Module
- func (m *Module) Clone(name string) onlineconfInterface.Module
- func (m *Module) GetBool(path string, d ...bool) (bool, error)
- func (m *Module) GetBoolIfExists(path string) (bool, bool, error)
- func (m *Module) GetDuration(path string, d ...time.Duration) (time.Duration, error)
- func (m *Module) GetDurationIfExists(path string) (time.Duration, bool, error)
- func (m *Module) GetInt(path string, d ...int64) (int64, error)
- func (m *Module) GetIntIfExists(path string) (int64, bool, error)
- func (m *Module) GetMmappedFile() *mmap.ReaderAt
- func (m *Module) GetString(path string, d ...string) (string, error)
- func (m *Module) GetStringIfExists(path string) (string, bool, error)
- func (m *Module) GetStrings(path string, defaultValue []string) ([]string, error)
- func (m *Module) GetStruct(path string, value interface{}) (bool, error)
- func (m *Module) RegisterSubscription(subscription onlineconfInterface.SubscriptionCallback)
- func (m *Module) Reopen(mmappedFile *mmap.ReaderAt) (*mmap.ReaderAt, error)
- type OnlineconfInstance
- func (oi *OnlineconfInstance) Clone() (onlineconfInterface.Instance, error)
- func (oi *OnlineconfInstance) GetBool(path string, d ...bool) (bool, error)
- func (oi *OnlineconfInstance) GetBoolIfExists(path string) (bool, bool, error)
- func (oi *OnlineconfInstance) GetConfigDir() string
- func (oi *OnlineconfInstance) GetDuration(path string, d ...time.Duration) (time.Duration, error)
- func (oi *OnlineconfInstance) GetDurationIfExists(path string) (time.Duration, bool, error)
- func (oi *OnlineconfInstance) GetInt(path string, d ...int64) (int64, error)
- func (oi *OnlineconfInstance) GetIntIfExists(path string) (int64, bool, error)
- func (oi *OnlineconfInstance) GetModule(name string) onlineconfInterface.Module
- func (oi *OnlineconfInstance) GetModuleByFile(fileName string) (onlineconfInterface.Module, bool)
- func (oi *OnlineconfInstance) GetModuleNames() []string
- func (oi *OnlineconfInstance) GetOrAddModule(name string) (onlineconfInterface.Module, error)
- func (oi *OnlineconfInstance) GetString(path string, d ...string) (string, error)
- func (oi *OnlineconfInstance) GetStringIfExists(path string) (string, bool, error)
- func (oi *OnlineconfInstance) GetStrings(path string, defaultValue []string) ([]string, error)
- func (oi *OnlineconfInstance) GetStruct(path string, value interface{}) (bool, error)
- func (oi *OnlineconfInstance) RegisterSubscription(module string, params []string, callback func() error) error
- func (oi *OnlineconfInstance) Release(ctx context.Context, cloned onlineconfInterface.Instance) error
- func (oi *OnlineconfInstance) StartWatcher(ctx context.Context) error
- func (oi *OnlineconfInstance) StopWatcher() error
- type OnlineconfWatcher
- type SubscriptionCallback
Constants ¶
const ContextOnlineconfName ctxKey = iota
const DefaultModule = "TREE"
Variables ¶
var ErrAddModule = errors.New("add module error")
var ErrFormatIsNotJSON = errors.New("format is not JSON")
Functions ¶
func GetBool ¶
GetBool reads an bool value of a named parameter from the module "TREE". It returns this value if the parameter exists and is a bool. In the other case it panics unless default value is provided in the second argument.
func GetBoolIfExists ¶
GetBoolIfExists reads an bool value of a named parameter from the module "TREE". It returns this value and the boolean true if the parameter exists and is a bool. In the other case it returns the boolean false and 0.
func GetDuration ¶ added in v0.9.4
GetDuration reads an string value and parse to time.Duration of a named parameter from the module "TREE". It returns this value if the parameter exists and is an integer. In the other case it panics unless default value is provided in the second argument.
func GetDurationIfExists ¶ added in v0.9.4
GetDurationIfExists reads an string value of a named parameter from the module "TREE" and parse it to time.Duration. It returns this value and the boolean true if the parameter exists and is an integer. In the other case it returns the boolean false and 0.
func GetInt ¶
GetInt reads an integer value of a named parameter from the module "TREE". It returns this value if the parameter exists and is an integer. In the other case it panics unless default value is provided in the second argument.
func GetIntIfExists ¶
GetIntIfExists reads an integer value of a named parameter from the module "TREE". It returns this value and the boolean true if the parameter exists and is an integer. In the other case it returns the boolean false and 0.
func GetOrAddModule ¶
func GetString ¶
GetString reads a string value of a named parameter from the module "TREE". It returns this value if the parameter exists and is a string. In the other case it panics unless default value is provided in the second argument.
func GetStringIfExists ¶
GetStringIfExists reads a string value of a named parameter from the module "TREE". It returns the boolean true if the parameter exists and is a string. In the other case it returns the boolean false and an empty string.
func GetStrings ¶
GetStrings reads a []string value of a named parameter from the module "TREE". It returns this value if the parameter exists and is a comma-separated string or JSON array. In the other case it returns a default value provided in the second argument.
func GetStruct ¶
GetStruct reads a structured value of a named parameter from the module "TREE". It stores this value in the value pointed by the value argument and returns true if the parameter exists and was unmarshaled successfully. In the case of error or if the parameter is not exists, the function doesn't touch the value argument, so you can safely pass a default value as the value argument and completely ignore return values of this function. A value is unmarshaled from JSON using json.Unmarshal and is cached internally until the configuration is updated, so be careful to not modify values returned by a reference. Experimental: this function can be modified or removed without any notice.
func Initialize ¶
func Initialize(ctx context.Context, options ...onlineconfInterface.Option) (context.Context, error)
Initialize sets config directory for onlineconf modules. Default value is "/usr/local/etc/onlineconf"
func RegisterSubscription ¶
func StartWatcher ¶
func StopWatcher ¶
func WithConfigDir ¶
func WithConfigDir(path string) options
func WithLogger ¶
func WithLogger(logger onlineconfInterface.Logger) options
func WithModules ¶
Types ¶
type DefaultLogger ¶
type DefaultLogger struct{}
func (*DefaultLogger) Error ¶
func (l *DefaultLogger) Error(ctx context.Context, msg string, args ...any)
type Module ¶
func (*Module) GetBool ¶
GetBool reads an bool value of a named parameter from the module. It returns this value if the parameter exists and is a bool. In the other case it return error unless default value is provided in the second argument.
func (*Module) GetBoolIfExists ¶
GetBoolIfExists reads an integer value of a named parameter from the module. It returns this value and the boolean true if the parameter exists and is an bool. In the other case it returns the boolean false and 0.
func (*Module) GetDuration ¶ added in v0.9.4
GetDuration reads an string value of a named parameter from the module and parse it to time.Duration. It returns this value if the parameter exists and is an time.Duration. In the other case it return error unless default value is provided in the second argument.
func (*Module) GetDurationIfExists ¶ added in v0.9.4
GetDuration reads an string value of a named parameter from the module and parse it to time.Duration. It returns this value if the parameter exists and is an time.Duration. In the other case it return error unless default value is provided in the second argument.
func (*Module) GetInt ¶
GetInt reads an integer value of a named parameter from the module. It returns this value if the parameter exists and is an integer. In the other case it return error unless default value is provided in the second argument.
func (*Module) GetIntIfExists ¶
GetIntIfExists reads an integer value of a named parameter from the module. It returns this value and the boolean true if the parameter exists and is an integer. In the other case it returns the boolean false and 0.
func (*Module) GetMmappedFile ¶
func (*Module) GetString ¶
GetString reads a string value of a named parameter from the module. It returns this value if the parameter exists and is a string. In the other case it return error unless default value is provided in the second argument.
func (*Module) GetStringIfExists ¶
GetStringIfExists reads a string value of a named parameter from the module. It returns the boolean true if the parameter exists and is a string. In the other case it returns the boolean false and an empty string.
func (*Module) GetStrings ¶
GetStrings reads a []string value of a named parameter from the module. It returns this value if the parameter exists and is a comma-separated string or JSON array. In the other case it returns a default value provided in the second argument.
func (*Module) GetStruct ¶
GetStruct reads a structured value of a named parameter from the module. It stores this value in the value pointed by the value argument and returns true if the parameter exists and was unmarshaled successfully. In the case of error or if the parameter is not exists, the method doesn't touch the value argument, so you can safely pass a default value as the value argument and completely ignore return values of this method. A value is unmarshaled from JSON using json.Unmarshal and is cached internally until the configuration is updated, so be careful to not modify values returned by a reference. Experimental: this method can be modified or removed without any notice.
func (*Module) RegisterSubscription ¶
func (m *Module) RegisterSubscription(subscription onlineconfInterface.SubscriptionCallback)
type OnlineconfInstance ¶
func Create ¶
func Create(options ...onlineconfInterface.Option) *OnlineconfInstance
Initialize sets config directory for onlineconf modules.
func FromContext ¶
func FromContext(ctx context.Context) *OnlineconfInstance
func (*OnlineconfInstance) Clone ¶
func (oi *OnlineconfInstance) Clone() (onlineconfInterface.Instance, error)
func (*OnlineconfInstance) GetBool ¶
func (oi *OnlineconfInstance) GetBool(path string, d ...bool) (bool, error)
GetBool reads an bool value of a named parameter from the module "TREE". It returns this value if the parameter exists and is a bool. In the other case it panics unless default value is provided in the second argument.
func (*OnlineconfInstance) GetBoolIfExists ¶
func (oi *OnlineconfInstance) GetBoolIfExists(path string) (bool, bool, error)
GetBoolIfExists reads an bool value of a named parameter from the module "TREE". It returns this value and the boolean true if the parameter exists and is a bool. In the other case it returns the boolean false and 0.
func (*OnlineconfInstance) GetConfigDir ¶
func (oi *OnlineconfInstance) GetConfigDir() string
func (*OnlineconfInstance) GetDuration ¶ added in v0.9.4
GetDuration reads an string value of a named parameter from the module "TREE" and parse it to time.Duration. It returns this value if the parameter exists and is an integer. In the other case it panics unless default value is provided in the second argument.
func (*OnlineconfInstance) GetDurationIfExists ¶ added in v0.9.4
GetIntIfExists reads an integer value of a named parameter from the module "TREE". It returns this value and the boolean true if the parameter exists and is an integer. In the other case it returns the boolean false and 0.
func (*OnlineconfInstance) GetInt ¶
func (oi *OnlineconfInstance) GetInt(path string, d ...int64) (int64, error)
GetInt reads an integer value of a named parameter from the module "TREE". It returns this value if the parameter exists and is an integer. In the other case it panics unless default value is provided in the second argument.
func (*OnlineconfInstance) GetIntIfExists ¶
func (oi *OnlineconfInstance) GetIntIfExists(path string) (int64, bool, error)
GetIntIfExists reads an integer value of a named parameter from the module "TREE". It returns this value and the boolean true if the parameter exists and is an integer. In the other case it returns the boolean false and 0.
func (*OnlineconfInstance) GetModule ¶
func (oi *OnlineconfInstance) GetModule(name string) onlineconfInterface.Module
GetModule returns a named module.
func (*OnlineconfInstance) GetModuleByFile ¶
func (oi *OnlineconfInstance) GetModuleByFile(fileName string) (onlineconfInterface.Module, bool)
func (*OnlineconfInstance) GetModuleNames ¶
func (oi *OnlineconfInstance) GetModuleNames() []string
func (*OnlineconfInstance) GetOrAddModule ¶
func (oi *OnlineconfInstance) GetOrAddModule(name string) (onlineconfInterface.Module, error)
GetModule returns a named module.
func (*OnlineconfInstance) GetString ¶
func (oi *OnlineconfInstance) GetString(path string, d ...string) (string, error)
GetString reads a string value of a named parameter from the module "TREE". It returns this value if the parameter exists and is a string. In the other case it panics unless default value is provided in the second argument.
func (*OnlineconfInstance) GetStringIfExists ¶
func (oi *OnlineconfInstance) GetStringIfExists(path string) (string, bool, error)
GetStringIfExists reads a string value of a named parameter from the module "TREE". It returns the boolean true if the parameter exists and is a string. In the other case it returns the boolean false and an empty string.
func (*OnlineconfInstance) GetStrings ¶
func (oi *OnlineconfInstance) GetStrings(path string, defaultValue []string) ([]string, error)
GetStrings reads a []string value of a named parameter from the module "TREE". It returns this value if the parameter exists and is a comma-separated string or JSON array. In the other case it returns a default value provided in the second argument.
func (*OnlineconfInstance) GetStruct ¶
func (oi *OnlineconfInstance) GetStruct(path string, value interface{}) (bool, error)
GetStruct reads a structured value of a named parameter from the module "TREE". It stores this value in the value pointed by the value argument and returns true if the parameter exists and was unmarshaled successfully. In the case of error or if the parameter is not exists, the function doesn't touch the value argument, so you can safely pass a default value as the value argument and completely ignore return values of this function. A value is unmarshaled from JSON using json.Unmarshal and is cached internally until the configuration is updated, so be careful to not modify values returned by a reference. Experimental: this function can be modified or removed without any notice.
func (*OnlineconfInstance) RegisterSubscription ¶
func (oi *OnlineconfInstance) RegisterSubscription(module string, params []string, callback func() error) error
func (*OnlineconfInstance) Release ¶
func (oi *OnlineconfInstance) Release(ctx context.Context, cloned onlineconfInterface.Instance) error
func (*OnlineconfInstance) StartWatcher ¶
func (oi *OnlineconfInstance) StartWatcher(ctx context.Context) error
func (*OnlineconfInstance) StopWatcher ¶
func (oi *OnlineconfInstance) StopWatcher() error
type OnlineconfWatcher ¶
type SubscriptionCallback ¶
type SubscriptionCallback struct {
// contains filtered or unexported fields
}
func NewSubscription ¶
func NewSubscription(params []string, callback func() error) *SubscriptionCallback
func (*SubscriptionCallback) GetPaths ¶
func (s *SubscriptionCallback) GetPaths() []string
func (*SubscriptionCallback) InvokeCallback ¶
func (s *SubscriptionCallback) InvokeCallback() error