conf

package module
v0.0.0-...-6f330c7 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2014 License: GPL-2.0 Imports: 7 Imported by: 0

README

conf

YAML Configuration Reader

Note

All configurations files used by the conf package should be located under /usr/local/conf unless you change that folder in the conf.go source file.

Usage

Import the Trulioo/conf package into your go source.

After the program initialisation, a Conf variable will be created that holds your configuration. The configuration itself will be loaded from a YAML file with the name of your program, followed by "-" and the value of the -env parameter passed to it (by default "local"), and with a suffix of ".yml".

E.g. if your program is called program and you want to run in a production environment, then you would start it using ./program -env=prod and your configuration file should be named program-prod.yml and located under /usr/local/conf

In your program, if you need to access any configuration element, first save the configuration in a variable, using conf.GetConf().

You can get access to any element in the configuration using its path. You will use FindNode(conf.Conf,"element.subelement") for that purpose. FindNode returns an interface{} and an error.

If you want to save yourself the hard work dealing with interface{} elements, you can use 3 helpers:

  • GetString(path string) (string,error) will return the string located at path
  • GetList(interface{}) ([]yaml.Node,error) will return you an array of Yaml Nodes (not necessarily better to deal with)
  • GetStringsMap(path string) (map[string]string,error) will return you a map of string elements corresponding to the path informed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindNode

func FindNode(element interface{}, path string) (interface{}, error)

func GetList

func GetList(element interface{}) ([]yaml.Node, error)

func GetString

func GetString(path string) (string, error)

func ReadNode

func ReadNode(element yaml.Node) (interface{}, error)

Types

type YamlConf

type YamlConf struct {
	File *yaml.File
	Root yaml.Node
	Conf interface{}
}
var (
	Conf *YamlConf
)

func GetConf

func GetConf() *YamlConf

func ReadFile

func ReadFile(name string) (*YamlConf, error)

func (*YamlConf) GetStringsMap

func (config *YamlConf) GetStringsMap(path string) (stringMap map[string]string, err error)

func (*YamlConf) Read

func (theconf *YamlConf) Read() (interface{}, error)

Jump to

Keyboard shortcuts

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