Documentation ¶
Index ¶
- Constants
- Variables
- func Clone(from, to context.Context) (context.Context, error)
- func Create(options ...onlineconfInterface.Option) onlineconfInterface.Instance
- func Encode(i interface{}) []byte
- func GetBool(ctx context.Context, path string, d ...bool) (bool, error)
- func GetBoolIfExists(ctx context.Context, path string) (bool, bool, error)
- func GetInt(ctx context.Context, path string, d ...int) (int, error)
- func GetIntIfExists(ctx context.Context, path string) (int, 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 NewSubscription(params []string, callback func() error) onlineconfInterface.SubscriptionCallback
- 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) onlineconfInterface.Option
- func WithLogger(logger onlineconfInterface.Logger) onlineconfInterface.Option
- func WithModules(moduleNames []string, required bool) onlineconfInterface.Option
- 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) GetInt(path string, d ...int) (int, error)
- func (m *Module) GetIntIfExists(path string) (int, 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) GetInt(path string, d ...int) (int, error)
- func (oi *OnlineconfInstance) GetIntIfExists(path string) (int, 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(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 Create ¶
func Create(options ...onlineconfInterface.Option) onlineconfInterface.Instance
Initialize sets config directory for onlineconf modules.
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 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 NewSubscription ¶ added in v0.0.2
func NewSubscription(params []string, callback func() error) onlineconfInterface.SubscriptionCallback
func RegisterSubscription ¶
func StartWatcher ¶
func StopWatcher ¶
func WithConfigDir ¶
func WithConfigDir(path string) onlineconfInterface.Option
func WithLogger ¶
func WithLogger(logger onlineconfInterface.Logger) onlineconfInterface.Option
func WithModules ¶ added in v0.0.2
func WithModules(moduleNames []string, required bool) onlineconfInterface.Option
Types ¶
type DefaultLogger ¶
type DefaultLogger struct{}
func (*DefaultLogger) Error ¶
func (l *DefaultLogger) Error(ctx context.Context, msg string, args ...any)
type Module ¶
func (*Module) Clone ¶ added in v0.0.2
func (m *Module) Clone(name string) onlineconfInterface.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) 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 ¶ added in v0.0.2
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 FromContext ¶
func FromContext(ctx context.Context) *OnlineconfInstance
func (*OnlineconfInstance) Clone ¶ added in v0.0.2
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 ¶ added in v0.0.2
func (oi *OnlineconfInstance) GetConfigDir() string
func (*OnlineconfInstance) GetInt ¶
func (oi *OnlineconfInstance) GetInt(path string, d ...int) (int, 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) (int, 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 ¶ added in v0.0.2
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 ¶ added in v0.0.2
func (oi *OnlineconfInstance) Release(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 (*SubscriptionCallback) GetPaths ¶ added in v0.0.2
func (s *SubscriptionCallback) GetPaths() []string
func (*SubscriptionCallback) InvokeCallback ¶ added in v0.0.2
func (s *SubscriptionCallback) InvokeCallback() error