Documentation ¶
Index ¶
- type ConfigItemNotFound
- type ConfigNotConfiguredError
- type ConfigNotImplementedError
- type ConfigTypeMismatchError
- type ConfigUsageError
- type HJSONConfig
- func (fl *HJSONConfig) CheckExternalConfig() (err error)
- func (fl *HJSONConfig) GetBooleanValue(path ...string) (b bool, err error)
- func (fl *HJSONConfig) GetIntValue(path ...string) (i int, err error)
- func (fl *HJSONConfig) GetStringValue(path ...string) (s string, err error)
- func (fl *HJSONConfig) GetSubconfig(path ...string) (c IConfig, err error)
- func (fl *HJSONConfig) GetValue(path ...string) (i interface{}, err error)
- func (fl *HJSONConfig) LoadFileContents(filename string) (cnt []byte, err error)
- func (fl *HJSONConfig) ParseStringContents(cnt []byte) (m map[string]interface{}, err error)
- func (fl *HJSONConfig) ReloadInternalMap() (err error)
- func (fl *HJSONConfig) SetDefaultLoadSetting(sl ...interface{}) (err error)
- type HJSONConfigError
- type IConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigItemNotFound ¶
type ConfigItemNotFound struct {
// contains filtered or unexported fields
}
ConfigItemNotFound is intended for misconfiguration cases
func NewConfigItemNotFound ¶
func NewConfigItemNotFound(s string) *ConfigItemNotFound
NewConfigItemNotFound generates error object
func (*ConfigItemNotFound) Error ¶
func (e *ConfigItemNotFound) Error() string
Error is standard error interface h
type ConfigNotConfiguredError ¶
type ConfigNotConfiguredError struct {
// contains filtered or unexported fields
}
ConfigNotConfiguredError is for cases if comesthing is not implemented we implement standard error interface
func NewConfigNotConfiguredError ¶
func NewConfigNotConfiguredError(s string) *ConfigNotConfiguredError
NewConfigNotConfiguredError generates error object
func (*ConfigNotConfiguredError) Error ¶
func (e *ConfigNotConfiguredError) Error() string
Error is standard error interface h
type ConfigNotImplementedError ¶
type ConfigNotImplementedError struct {
// contains filtered or unexported fields
}
ConfigNotImplementedError is for cases if comesthing is not implemented we implement standard error interface
func NewConfigNotImplementedError ¶
func NewConfigNotImplementedError(s string) *ConfigNotImplementedError
NewConfigNotImplementedError generates error object
func (*ConfigNotImplementedError) Error ¶
func (e *ConfigNotImplementedError) Error() string
Error is standard error interface method
type ConfigTypeMismatchError ¶
type ConfigTypeMismatchError struct {
// contains filtered or unexported fields
}
ConfigTypeMismatchError is intended for case we get value from object of wrong type
func NewConfigTypeMismatchError ¶
func NewConfigTypeMismatchError(s string) *ConfigTypeMismatchError
NewConfigTypeMismatchError generates error object
func (*ConfigTypeMismatchError) Error ¶
func (e *ConfigTypeMismatchError) Error() string
Error is standard error interface h
type ConfigUsageError ¶
type ConfigUsageError struct {
// contains filtered or unexported fields
}
ConfigUsageError is intended for misconfiguration cases
func NewConfigUsageError ¶
func NewConfigUsageError(s string) *ConfigUsageError
NewConfigUsageError generates error object
func (*ConfigUsageError) Error ¶
func (e *ConfigUsageError) Error() string
Error is standard error interface h
type HJSONConfig ¶
type HJSONConfig struct {
// contains filtered or unexported fields
}
HJSONConfig is configuration loader HJSON interface
func NewHJSONConfig ¶
func NewHJSONConfig(sl ...interface{}) (fl *HJSONConfig, err error)
NewHJSONConfig creates new object or gives err0r all arguments are same as HJSONConfig.SetDefaultLoadSetting
func (*HJSONConfig) CheckExternalConfig ¶
func (fl *HJSONConfig) CheckExternalConfig() (err error)
CheckExternalConfig checks external configuration file and it's contents - e.g.check file before reload
func (*HJSONConfig) GetBooleanValue ¶
func (fl *HJSONConfig) GetBooleanValue(path ...string) (b bool, err error)
GetBooleanValue returns boolean value or error by path
func (*HJSONConfig) GetIntValue ¶
func (fl *HJSONConfig) GetIntValue(path ...string) (i int, err error)
GetIntValue returns integer value by path
func (*HJSONConfig) GetStringValue ¶
func (fl *HJSONConfig) GetStringValue(path ...string) (s string, err error)
GetStringValue returns string value or error by path
func (*HJSONConfig) GetSubconfig ¶
func (fl *HJSONConfig) GetSubconfig(path ...string) (c IConfig, err error)
GetSubconfig returns config interface or nil + error
func (*HJSONConfig) GetValue ¶
func (fl *HJSONConfig) GetValue(path ...string) (i interface{}, err error)
GetValue get any type value on programmer mind own usage on initialized object: fl.GetValue("a", "b", "c", "d") on this function would be based functions below
func (*HJSONConfig) LoadFileContents ¶
func (fl *HJSONConfig) LoadFileContents(filename string) (cnt []byte, err error)
LoadFileContents load contents of file. separate function to make tests possible
func (*HJSONConfig) ParseStringContents ¶
func (fl *HJSONConfig) ParseStringContents(cnt []byte) (m map[string]interface{}, err error)
ParseStringContents parses HJSON - separated to method cause I want test that
func (*HJSONConfig) ReloadInternalMap ¶
func (fl *HJSONConfig) ReloadInternalMap() (err error)
ReloadInternalMap (re)loads internal map - if from file. If not - says ConfigUsageError
func (*HJSONConfig) SetDefaultLoadSetting ¶
func (fl *HJSONConfig) SetDefaultLoadSetting(sl ...interface{}) (err error)
SetDefaultLoadSetting sets default config file for loader
type HJSONConfigError ¶
type HJSONConfigError struct {
// contains filtered or unexported fields
}
HJSONConfigError inform when hjson error occurred there
func NewHJSONConfigError ¶
func NewHJSONConfigError(s string) *HJSONConfigError
NewHJSONConfigError generates error object
func (*HJSONConfigError) Error ¶
func (e *HJSONConfigError) Error() string
Error is standard error interface h
type IConfig ¶
type IConfig interface { // Set default config load settings. In case of file loader - filename // if first argument is map object -build config from this map object SetDefaultLoadSetting(sl ...interface{}) (err error) // checks external configuration file and it's contents - for example for reload or restart purposes CheckExternalConfig() (err error) // (re)loads internal map ReloadInternalMap() (err error) // get variant type value GetValue(path ...string) (i interface{}, err error) // functions below will try make from this variant value typed value // returns integer value by path GetIntValue(path ...string) (i int, err error) // returns string value or error by path GetStringValue(path ...string) (s string, err error) // returns boolean value GetBooleanValue(path ...string) (b bool, err error) // returns config interface or nil + error GetSubconfig(path ...string) (c IConfig, err error) }
IConfig is basic interface for all optional configuration structures
func GetConfigInstance ¶
GetConfigInstance get instans of config depending of wanted config format for now supported only HJSON format tag is intended not to load configuration files twice and store object hash map inside module thats done specially not to create config instance twice + get already created instance How to call: GetConfigInstance(tag, format, list_of_settings...) tag used not to load config twice. If you need reload them just use CheckExternalConfig() and ReloadInternalMap() format: for now HJSON|hjson|JSON|json this parameter added for future features(may be we would add other configuration formats there) if it was loaded from file. settings must contain config type as first argument and other parameters SetDefaultLoadSetting need For example. First call when we want load configuration file is: GetConfigInstance("mainconfig", "HJSON", "/etc/file.hjson") When you need get instance again, you just must call: GetConfigInstance("mainconfig") and you will get them from internal hash this all is intended not to put variable withyou configuration everywhere. if you do not want tagging and every time get new object, use nil tag e.g. GetConfigInstance(nil, "HJSON", "/etc/file.hjson")