package module
Version: v0.0.0-...-2a71b5b Latest Latest

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

Go to latest
Published: Jul 23, 2015 License: MIT Imports: 4 Imported by: 0


JsonConf GoDoc


JsonConf implements a method of reading environment variables and defaulting to a configuration json file if the environment variable is not found.

This helps setup a single configuration file that can be used in production, development and local environments, while all having different configurations if the appropriate environment variables are setup.

###Full example

package main

import (

func main() {
	redisaddr, err := jsonconf.GetVar("REDIS_ADDR"))
	if (err != nil){
		fmt.Println(err) // No key found

Full package and usage documentation can be located at the godocs site.




This section is empty.


View Source
var Conf map[string]interface{}

Conf is a global variable that will map a given string to an interface generated from the JSON file. It will be loaded with values on initial LoadConfig call.


func GetVar

func GetVar(v string, defaultVal ...string) (string, error)

GetVar will, given the name of a string, try to locate an environment variable that matches the string. If that match comes empty, then it will look in the configuration file for the string as a key. If that match comes up empty, the optional second parameter will be used as a default value. If it's not present, then the call will return an error. Otherwise, it will return the string of the interface{} stored in Conf or the default as appropriate

func LoadConfig

func LoadConfig(filename string) error

LoadConfig will, given a filename, load a json file from the location. It will then decode it and store it into the global Conf variable

func SetVar

func SetVar(k string, v string)

SetVar sets the given key, provided as a string, to the given string value. This is useful in overwriting values if need be, or adding values to the conf so that they can be globally accessible.


This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL