onlineconf

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 14 Imported by: 1

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 Create

Initialize sets config directory for onlineconf modules.

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 GetInt

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

func GetIntIfExists(ctx context.Context, 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 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 added in v0.0.2

func MakePath(s ...string) string

func NewSubscription added in v0.0.2

func NewSubscription(params []string, callback func() error) onlineconfInterface.SubscriptionCallback

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) 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)

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 added in v0.0.2

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) GetInt

func (m *Module) GetInt(path string, d ...int) (int, 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) (int, 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 added in v0.0.2

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 added in v0.0.2

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

type OnlineconfInstance

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

func FromContext

func FromContext(ctx context.Context) *OnlineconfInstance

func (*OnlineconfInstance) Clone added in v0.0.2

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

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

Jump to

Keyboard shortcuts

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