onlineconf

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 13 Imported by: 0

README

onlineconf

Go package onlineconf reads configuration files generated by OnlineConf.

Example

Read parameters from a module:

module := onlineconf.GetModule("module")
s := module.GetString("/my/parameter", "default value")
i := module.GetInt("/my/parameter", 300)

Reading parameters from the module "TREE" can be simpler:

s := onlineconf.GetString("/my/parameter", "default value")
i := onlineconf.GetInt("/my/parameter", 300)

Documentation

Overview

Package onlineconf reads configuration files generated by OnlineConf.

It opens indexed CDB files and maps them in the memory. If OnlineConf modifies them then they are automatically reopened.

Index

Constants

This section is empty.

Variables

View Source
var ErrFormatIsNotJSON = errors.New("format is not JSON")

Functions

func GetBool

func GetBool(path string, d ...bool) bool

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(path string) (bool, bool)

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(path string, d ...int) int

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(path string) (int, bool)

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 GetString

func GetString(path string, d ...string) string

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(path string) (string, bool)

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(path string, defaultValue []string) []string

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(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(newConfigDir string)

Initialize sets config directory for onlineconf modules. Default value is "/usr/local/etc/onlineconf"

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output destination for the standard logger.

Types

type Module

type Module struct {
	// contains filtered or unexported fields
}

func GetModule

func GetModule(name string) *Module

GetModule returns a named module.

func (*Module) GetBool

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

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 panics unless default value is provided in the second argument.

func (*Module) GetBoolIfExists

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

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

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 panics unless default value is provided in the second argument.

func (*Module) GetIntIfExists

func (m *Module) GetIntIfExists(path string) (int, bool)

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

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

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 panics unless default value is provided in the second argument.

func (*Module) GetStringIfExists

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

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

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.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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