Documentation ¶
Overview ¶
Package onlineconf reads configuration files generated by OnlineConf.
It opens indexed CDB files and maps them in the memory. If onlineconf-updater modifies them, they are automatically reopened.
Index ¶
- Constants
- Variables
- type Mod
- func (m *Mod) Bool(path string) (bool, bool)
- func (m *Mod) BoolWithDef(path string, defaultValue bool) (bool, bool)
- func (m *Mod) Int(path string) (int, bool)
- func (m *Mod) IntWithDef(path string, defaultValue int) (int, bool)
- func (m *Mod) MapIntInt(path string) (map[int]int, bool)
- func (m *Mod) MapIntIntWithDef(path string, defaultValue map[int]int) (map[int]int, bool)
- func (m *Mod) MapIntString(path string) (map[int]string, bool)
- func (m *Mod) MapIntStringWithDef(path string, defaultValue map[int]string) (map[int]string, bool)
- func (m *Mod) MapStringInt(path string) (map[string]int, bool)
- func (m *Mod) MapStringIntWithDef(path string, defaultValue map[string]int) (map[string]int, bool)
- func (m *Mod) MapStringInterface(path string) (map[string]interface{}, bool)
- func (m *Mod) MapStringInterfaceWithDef(path string, defaultValue map[string]interface{}) (map[string]interface{}, bool)
- func (m *Mod) MapStringString(path string) (map[string]string, bool)
- func (m *Mod) MapStringStringWithDef(path string, defaultValue map[string]string) (map[string]string, bool)
- func (m *Mod) MustBool(path string) bool
- func (m *Mod) MustInt(path string) int
- func (m *Mod) MustMapIntInt(path string) map[int]int
- func (m *Mod) MustMapIntString(path string) map[int]string
- func (m *Mod) MustMapStringInt(path string) map[string]int
- func (m *Mod) MustMapStringInterface(path string) map[string]interface{}
- func (m *Mod) MustMapStringString(path string) map[string]string
- func (m *Mod) MustRawJSON(path string) string
- func (m *Mod) MustString(path string) string
- func (m *Mod) RawJSON(path string) (string, bool)
- func (m *Mod) RawJSONWithDef(path string, defaultValue string) (string, bool)
- func (m *Mod) String(path string) (string, bool)
- func (m *Mod) StringWithDef(path string, defaultValue string) (string, bool)
- func (m *Mod) WithContext(ctx context.Context) context.Context
- type ModuleReloader
- type ReloaderOptions
Constants ¶
const DefaultModulesDir = "/usr/local/etc/onlineconf"
DefaultModulesDir defines default directory for modules
Variables ¶
var ErrInvalidCDB = errors.New("cdb is inconsistent")
ErrInvalidCDB means that cdb is invalid
Functions ¶
This section is empty.
Types ¶
type Mod ¶
type Mod struct { StringParams map[string]string IntParams map[string]int RawJSONParams map[string]string // Here will be all JSON params (not parsed) MapStringInterfaceParams map[string]map[string]interface{} MapIntIntParams map[string]map[int]int MapIntStringParams map[string]map[int]string MapStringIntParams map[string]map[string]int MapStringStringParams map[string]map[string]string }
Mod is a structure that associated with onlineconf module file.
func Module ¶
Module returns current copy of Module by name in default onlineconf module directory. This function is STRONGLY NOT RECOMENDED FOR USE. It is very unefficient. This module will never be updated. This function parses all the parameters in onlineconf and copies it to memory. Thats why this operations is expencive. You should prefer to use ModuleReloader if its possible.
func ModuleFromContext ¶
ModuleFromContext retrieves a config module from context.
func MustModule ¶
MustModule returns Module by name in default onlineconf module directory. Panics on error. This module will never be updated. This function parses all the parameters in onlineconf and copies it to memory. Thats why this operations is expencive. You should prefer to use ModuleReloader if its possible.
func MustTree ¶
func MustTree() *Mod
MustTree returns Module TREE in default onlineconf module directory Panics on error. This module will never be updated. This function parses all the parameters in onlineconf and copies it to memory. Thats why this operations is expencive. You should prefer to use ModuleReloader if its possible.
func NewModule ¶
NewModule parses cdb file and copies all content to local maps. Module returned by this method will never be updated
func Tree ¶
Tree returns current copy of Module TREE in default onlineconf module directory. This module will never be updated. This function parses all the parameters in onlineconf and copies it to memory. Thats why this operations is expencive. You should prefer to use ModuleReloader if its possible.
func (*Mod) Bool ¶
Bool returns bool interpretation of param. If length of string parameter with same path is greater than 0, returns true. In other case false.
func (*Mod) BoolWithDef ¶
BoolWithDef the same as Bool but is no such parameter? it returns default value
func (*Mod) Int ¶
Int returns value of a named parameter from the module. It returns the boolean true if the parameter exists and is an int. In the other case it returns the boolean false and zero.
func (*Mod) IntWithDef ¶
IntWithDef returns value of a named parameter from the module. It returns the boolean true if the parameter exists and is an int. In the other case it returns the boolean false and zero.
func (*Mod) MapIntIntWithDef ¶
MapIntIntWithDef default valur will not be copied!
func (*Mod) MapIntString ¶
MapIntString
func (*Mod) MapIntStringWithDef ¶
MapIntStringWithDef default valur will not be copied!
func (*Mod) MapStringInt ¶
MapStringInt
func (*Mod) MapStringIntWithDef ¶
MapStringIntWithDef default valur will not be copied!
func (*Mod) MapStringInterface ¶
MapStringInterface Interfaces will not be copied!
func (*Mod) MapStringInterfaceWithDef ¶
func (m *Mod) MapStringInterfaceWithDef(path string, defaultValue map[string]interface{}) (map[string]interface{}, bool)
MapStringInterfaceWithDef default valur will not be copied!
func (*Mod) MapStringString ¶
MapStringString
func (*Mod) MapStringStringWithDef ¶
func (m *Mod) MapStringStringWithDef(path string, defaultValue map[string]string) (map[string]string, bool)
MapStringStringWithDef default valur will not be copied!
func (*Mod) MustBool ¶
MustBool returns value of a named parameter from the module. It panics if no such parameter or this parameter is not a string.
func (*Mod) MustInt ¶
MustInt returns value of a named parameter from the module. It panics if no such parameter or this parameter is not an int
func (*Mod) MustMapStringInterface ¶
func (*Mod) MustRawJSON ¶
func (*Mod) MustString ¶
MustString returns value of a named parameter from the module. It panics if no such parameter or this parameter is not a string.
func (*Mod) RawJSONWithDef ¶
RawJSONWithDef default valur will not be copied!
func (*Mod) String ¶
String returns 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 (*Mod) StringWithDef ¶
StringWithDef returns 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.
type ModuleReloader ¶
type ModuleReloader struct {
// contains filtered or unexported fields
}
ModuleReloader watchers for module updates and reloads it
func ModuleReloaderFromContext ¶
func ModuleReloaderFromContext(ctx context.Context) (*ModuleReloader, bool)
ModuleReloaderFromContext retrieves a config module from context.
func MustReloader ¶
func MustReloader(moduleName string) *ModuleReloader
MustReloader returns reloader for specified module. Panics on error.
func NewModuleReloader ¶
func NewModuleReloader(ops *ReloaderOptions) (*ModuleReloader, error)
NewModuleReloader creates new module reloader
func Reloader ¶
func Reloader(moduleName string) (*ModuleReloader, error)
Reloader returns reloader for specified module
func (*ModuleReloader) Close ¶
func (mr *ModuleReloader) Close() error
Close closes inofitify watcher. Module will not be updated anymore.
func (*ModuleReloader) Module ¶
func (mr *ModuleReloader) Module() *Mod
Module returns the last successfully updated version of module
func (*ModuleReloader) WithContext ¶
func (mr *ModuleReloader) WithContext(ctx context.Context) context.Context
WithContext returns a new Context that carries value module reloader
type ReloaderOptions ¶
type ReloaderOptions struct { Name string Dir string // default in `DefaultModulesDir` FilePath string }
ReloaderOptions specify loader options You can specify either FilePath or Name + Dir. If you sprcified only Name, DefaultModulesDir Dir will be used