Documentation ¶
Overview ¶
Package conf provides all functionality required for parsing and accessing configuration files. You can use a hjson/json/env files as configurations and access them recursively with dots
Index ¶
- type Config
- func (c *Config) Get(key string, def interface{}) interface{}
- func (c *Config) GetAsString(key string, def string) string
- func (c *Config) GetBoolean(key string, def bool) bool
- func (c *Config) GetFloat(key string, def float64) float64
- func (c *Config) GetFloatArray(key string, def []float64) []float64
- func (c *Config) GetInt(key string, def int) int
- func (c *Config) GetInt64(key string, def int64) int64
- func (c *Config) GetIntArray(key string, def []int) []int
- func (c *Config) GetMap(key string, def map[string]interface{}) map[string]interface{}
- func (c *Config) GetString(key string, def string) string
- func (c *Config) GetStringArray(key string, def []string) []string
- func (c *Config) GetUInt64(key string, def uint64) uint64
- func (c *Config) IsSet(key string) bool
- type EvaluatorFunction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { ConfigsMap map[string]interface{} EvaluatorFunctionsMap map[string]EvaluatorFunction }
Config object for accessing configurations as a map all files are parsed at Creation time and recursively added to the ConfigsMap. Its much better and easier to use Getter functions of the struct. But when accessing full config objects are needed they are available with GetMap function or throw the ConfigsMap object
func New ¶
func New(configDir string, envDir string, evalFunctions []EvaluatorFunction) (config *Config, err error)
New creates a new config parser with config files at path configDir. Argument envDir can be an empty string which will cause the function to ignore .env parsing Config files with extensions .hjson and .json will be opened at this point and all files will be parsed resulting in a fast access time If there are any Evaluation needed those will be applied when accessing variables All folders inside configDir will recursively scanned for .hjson and .json files and any config will be accessible by its relative path connected with dots An error may happen during reading files like access denied if the error causes
func (*Config) Get ¶
Get returns the raw interface{} value of a key You have to convert it to your desired type If you have used a custom EvaluatorFunction to generate the value simply cast the interface{} to your desired type
func (*Config) GetAsString ¶
GetAsString converts the value of the key to string and returns it, if the key does not exist returns the def value
func (*Config) GetBoolean ¶
GetBoolean checks if the value of the key can be converted to boolean or not if not or if the key does not exist returns the def value valid values are true,false,1,0
func (*Config) GetFloat ¶
GetFloat checks if the value of the key can be converted to float64 or not if not or if the key does not exist returns the def value
func (*Config) GetFloatArray ¶
GetFloatArray checks if the value of the key can be converted to []float64 or not if not or if the key does not exist returns the def value
func (*Config) GetInt ¶
GetInt checks if the value of the key can be converted to int or not if not or if the key does not exist returns the def value
func (*Config) GetInt64 ¶
GetInt64 checks if the value of the key can be converted to int64 or not if not or if the key does not exist returns the def value
func (*Config) GetIntArray ¶
GetIntArray checks if the value of the key can be converted to []int or not if not or if the key does not exist returns the def value
func (*Config) GetString ¶
GetString checks if the value of the key can be converted to string or not if not or if the key does not exist returns the def value
func (*Config) GetStringArray ¶
GetStringArray checks if the value of the key can be converted to []string or not if not or if the key does not exist returns the def value
type EvaluatorFunction ¶
type EvaluatorFunction interface { // Evaluate the input arguments and return the value // if an error happened just return the def value Eval(params []string, def interface{}) interface{} // Get the name of the function // Returned value of this function is the string // that is used inside config files to call this evaluator GetFunctionName() string }
EvaluatorFunction lets you create dynamic config values they act like functions inside your hjson/json files each function when called inside config files can have any number of arguments and they are passed to the Eval function.