Documentation ¶
Overview ¶
Package flexiconfig is a configuration package with the goal of being powerful but not be more complex than a configuration package should be.
FlexiConfig is a hierarchical system that will merge configs together based on the order that they are loaded. Later config loads will replace earlier settings if they overlap.
A core part of this package is the ability to load lua files. This gives you the ability to run a sub program in order to generate your config.
Index ¶
- type LuaLoader
- type Settings
- func (this *Settings) AddLuaLoader(name string, loader lua.LGFunction)
- func (this Settings) Get(path string, target interface{}) error
- func (this Settings) GetBool(path string, defaultValue bool) (bool, error)
- func (this Settings) GetFloat(path string, defaultValue float64) (float64, error)
- func (this Settings) GetInt(path string, defaultValue int64) (int64, error)
- func (this Settings) GetJSON() []byte
- func (this Settings) GetPrettyJSON(prefix, indent string) []byte
- func (this Settings) GetString(path string, defaultValue string) (string, error)
- func (this *Settings) LoadFile(path string) error
- func (this *Settings) LoadJSON(b []byte) error
- func (this *Settings) LoadJSONFile(path string) error
- func (this *Settings) LoadLuaFile(path string) error
- func (this *Settings) LoadLuaString(code string) error
- func (this *Settings) MergeSettings(newSettings map[string]interface{}) error
- func (this Settings) Print()
- func (this Settings) RawGet(path string) (interface{}, error)
- func (this Settings) RawSet(timid bool, path string, value interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LuaLoader ¶
LuaLoader is the type representing the function signature used to load custom lua modules.
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
Settings is the main type that holds the config and loads new configuration files.
func (*Settings) AddLuaLoader ¶
func (this *Settings) AddLuaLoader(name string, loader lua.LGFunction)
AddLuaLoader can be used to add a custom lua module to each lua-state that is used. Note that flexiconfig currently creates a new lua instance for every lua config file loaded.
func (Settings) GetBool ¶
GetBool returns a bool stored in the path. If the the path isn't defined it will return the defaultValue and an error.
func (Settings) GetFloat ¶
GetFloat returns a float stored in the path. If the the path isn't defined it will return the defaultValue and an error.
func (Settings) GetInt ¶
GetInt returns a int stored in the path. If the the path isn't defined it will return the defaultValue and an error.
func (Settings) GetJSON ¶
GetJSON returns the json representation of the current config. This is useful to retain a static copy of the settings for later.
func (Settings) GetPrettyJSON ¶
GetPrettyJSON returns a pretty formatted json of the current config
func (Settings) GetString ¶
GetString returns a string stored in the path. If the the path isn't defined it will return the defaultValue and an error.
func (*Settings) LoadFile ¶
LoadFile takes a path and attempts to load it with the proper loader based on extension.
func (*Settings) LoadJSON ¶
LoadJSON takes a byte slice, dejsonifys it, then stores the contents in the Settings object.
func (*Settings) LoadJSONFile ¶
LoadJSON takes a path to a .json file and loads it into the Settings object.
func (*Settings) LoadLuaFile ¶
LoadLuaFile is used to load a lua config file from a specified path
func (*Settings) LoadLuaString ¶
LoadLuaString is used to load a config file from a lua string.
func (*Settings) MergeSettings ¶
MergeSettings takes a new map[string]interface{} of settings and merges it into the existing one recursively.
func (Settings) Print ¶
func (this Settings) Print()
Print is a utility function to print out the settings as JSON
func (Settings) RawGet ¶
RawGet will return the interface{} of the value at a specific path, and error if the value cannot be found.
func (Settings) RawSet ¶
RawSet will set the value of the config at a specific path. "timid" is used to help describe how to treat values that are part of the path but not the proper type. For instance, given this config:given the path of
{"root": {"intermediate": 22}},
and this function call:
settings.RawSet(timid, "root:intermediate:value", "Hello World")
timid == 0 will replace "itermediate" with the required map timid == 1 will instead throw an error claiming to not be able to find the path.