onlineconf

package
v0.9.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ContextOnlineconfName ctxKey = iota
View Source
const DefaultModule = "TREE"

Variables

View Source
var ErrAddModule = errors.New("add module error")
View Source
var ErrFormatIsNotJSON = errors.New("format is not JSON")
View Source
var ErrUnavailableInRO = errors.New("unable to use in readonly instance")
View Source
var ErrUnavailableModifyRefcountRO = errors.New("can't modify refcount in RO instance")

Functions

func Clone

func Clone(from, to context.Context) (context.Context, error)

func GetBool

func GetBool(ctx context.Context, 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 GetBoolIfExists

func GetBoolIfExists(ctx context.Context, 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 GetDuration added in v0.9.4

func GetDuration(ctx context.Context, path string, d ...time.Duration) (time.Duration, error)

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

func GetDurationIfExists(ctx context.Context, path string) (time.Duration, bool, error)

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

func GetInt(ctx context.Context, 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 GetIntIfExists

func GetIntIfExists(ctx context.Context, 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 GetModule

func GetModule(ctx context.Context, name string) (onlineconfInterface.Module, error)

func GetOrAddModule

func GetOrAddModule(ctx context.Context, name string) (onlineconfInterface.Module, error)

func GetString

func GetString(ctx context.Context, 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 GetStringIfExists

func GetStringIfExists(ctx context.Context, 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 GetStrings

func GetStrings(ctx context.Context, 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 GetStruct

func GetStruct(ctx context.Context, 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 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 MakePath

func MakePath(s ...string) string

func RegisterSubscription

func RegisterSubscription(ctx context.Context, module string, params []string, callback func() error) error

func Release

func Release(main, cloned context.Context) error

func StartWatcher

func StartWatcher(ctx context.Context) error

func StopWatcher

func StopWatcher(ctx context.Context) error

func WithConfigDir

func WithConfigDir(path string) options

func WithLogger

func WithLogger(logger onlineconfInterface.Logger) options

func WithModules

func WithModules(moduleNames []string, required bool) options

Types

type DefaultLogger

type DefaultLogger struct{}

func (*DefaultLogger) Error

func (l *DefaultLogger) Error(ctx context.Context, msg string, args ...any)

func (*DefaultLogger) Fatal

func (l *DefaultLogger) Fatal(ctx context.Context, msg string, args ...any)

func (*DefaultLogger) Warn

func (l *DefaultLogger) Warn(ctx context.Context, msg string, args ...any)

type Module

type Module struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*Module) Clone

func (m *Module) Clone(name string) onlineconfInterface.Module

func (*Module) GetBool

func (m *Module) GetBool(path string, d ...bool) (bool, error)

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

func (m *Module) GetBoolIfExists(path string) (bool, bool, error)

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

func (m *Module) GetDuration(path string, d ...time.Duration) (time.Duration, error)

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

func (m *Module) GetDurationIfExists(path string) (time.Duration, bool, error)

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

func (m *Module) GetInt(path string, d ...int64) (int64, error)

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

func (m *Module) GetIntIfExists(path string) (int64, bool, error)

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 (m *Module) GetMmappedFile() *mmap.ReaderAt

func (*Module) GetString

func (m *Module) GetString(path string, d ...string) (string, error)

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

func (m *Module) GetStringIfExists(path string) (string, bool, error)

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

func (m *Module) GetStrings(path string, defaultValue []string) ([]string, error)

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

func (m *Module) GetStruct(path string, value interface{}) (bool, error)

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)

func (*Module) Reopen

func (m *Module) Reopen(mmappedFile *mmap.ReaderAt) (*mmap.ReaderAt, error)

type OnlineconfInstance

type OnlineconfInstance struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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 (*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

func (oi *OnlineconfInstance) GetDuration(path string, d ...time.Duration) (time.Duration, error)

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

func (oi *OnlineconfInstance) GetDurationIfExists(path string) (time.Duration, 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) 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

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 (*OnlineconfInstance) StartWatcher

func (oi *OnlineconfInstance) StartWatcher(ctx context.Context) error

func (*OnlineconfInstance) StopWatcher

func (oi *OnlineconfInstance) StopWatcher() error

type OnlineconfWatcher

type OnlineconfWatcher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL