config

package
v0.0.0-...-51019d0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2014 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Configuration file parser for JSON format.

go-config makes it simple to work with cascading configuration files. It allows you to use cascading configuration files (e.g. one configuration for every environment). You can define options for every environment in different configuration files and load them accordingly to the set environment.

Usage

Place your configuration files in a directory (e.g. config). Configuration files need to be valid JSON files, terminated by .json.

The following example loads and parses options from base.json in the config directory:

package main

import (
    "fmt"
    "github.com/hypebeast/go-config/config"
)

type BaseConfig struct {
    Host    string
    Port    int
}

func main() {
    // Initialize the config system
    config.Init("config", "")

    // Get the base config
    config.Get("base", &baseConfig)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(domain string, rawVal interface{}) (err error)

Get reads the config options for the given domain and writes the config options in the given struct. The rawValu must be a pointer to a structure that represents the structure of the JSON.

func Init

func Init(baseDir string, environment ...string)

Init sets the base directory (the directory that contains the configuration files) and the name of the environment variable that defines the active environment. If no environment variable is specified no cascading files will be loaded.

Types

type Config

type Config map[string]interface{}

type Configs

type Configs map[string]interface{}

Jump to

Keyboard shortcuts

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