cfg

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2016 License: MIT Imports: 5 Imported by: 1

README

Configuration loader for Go applications

GoDoc Build Status

Install

go get github.com/goburrow/cfg

Example

  • example.go
package main

import (
	"fmt"

	"github.com/goburrow/cfg"
)

func main() {
	keys := make(map[string]string)

	// DefaultLoader loads configuration from ini file "~/.config/myApp/config"
	// if it exists and environment variables starting with "myApp_".
	loader := cfg.DefaultLoader("myApp")
	err := loader.Load(keys)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(keys)
}
  • ~/.config/myApp/config
x = 0
y = 0

[point1]
x = 1
y = 2
  • Run:
$ env myApp_y=1 myApp_point1.x=3 ./example
map[x:0 y:1 point1.x:3 point1.y:2]

Documentation

Overview

Package cfg provides configuration file loaders for Go applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UserConfigPath

func UserConfigPath(appName, fileName string) string

UserConfigPath returns ~/.config/appName/fileName.

Types

type Loader

type Loader interface {
	Load(map[string]string) error
}

Loader is the configuration loader.

func DefaultLoader

func DefaultLoader(appName string) Loader

DefaultLoader returns a chain of loading ini files from: 1. ~/.config/appName/config 2. System environments variable with appName_ prefix

func NewOverridingChain

func NewOverridingChain(l ...Loader) Loader

NewOverridingChain returns a Loader which loads all configurations in the chain. Keys in later chain will override the same key from previous chain.

Directories

Path Synopsis
Package ini provides helpers for reading ini file
Package ini provides helpers for reading ini file
Package structs provides a function to unmarshal properties to structs.
Package structs provides a function to unmarshal properties to structs.

Jump to

Keyboard shortcuts

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