Documentation ¶
Overview ¶
Package conf lets you manage configuration files in the easiest way possible, without the unnecessary pain.
Example ¶
package main import ( "fmt" "github.com/thehowl/conf" ) type myConf struct { Name string Age int } const myConfString = `Name=Jack Age=19` func main() { c := myConf{} conf.LoadRaw(&c, []byte(myConfString)) fmt.Printf("%#v\n", c) }
Output:
Index ¶
- Variables
- func Escape(s string) string
- func Export(from interface{}, filename string) error
- func ExportRaw(from interface{}) ([]byte, error)
- func Load(into interface{}, filename string) error
- func LoadRaw(into interface{}, data []byte) error
- func MustExport(from interface{}, filename string)
- func MustExportRaw(from interface{}) []byte
- func MustLoad(into interface{}, filename string)
- func MustLoadRaw(into interface{}, data []byte)
- type FieldValue
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoFile = errors.New("conf: the configuration file doesn't exist") ErrNotAStruct = errors.New("conf: the passed into/from variable is not a pointer to a struct") )
The only custom errors this package will return.
Functions ¶
func ExportRaw ¶
ExportRaw can create a []byte that can then be loaded back by LoadRaw to get a struct's original form back. I suck at explaining stuff.
func MustExport ¶
func MustExport(from interface{}, filename string)
MustExport panics if Export returns an error, removing error checking from your code. For the lazy.
func MustExportRaw ¶
func MustExportRaw(from interface{}) []byte
MustExportRaw panics if ExportRaw returns an error, removing error checking from your code. For the lazy.
func MustLoad ¶
func MustLoad(into interface{}, filename string)
MustLoad has the same behaviour as Load, but panics if it returns an error.
func MustLoadRaw ¶
func MustLoadRaw(into interface{}, data []byte)
MustLoadRaw has the same behaviour as LoadRaw, but panics if it returns an error.
Types ¶
type FieldValue ¶
FieldValue is a field=value pair in the configuration.
func Parse ¶
func Parse(data []byte) []FieldValue
Parse converts some bytes into various FieldValue pairs.