Skip to content

chen-keinan/go-simple-config

Repository files navigation

Go Report Card License test coverage badge Gitter


simple-config.png logo

go-simple-config

Go Simple config is an open source configuration lib for storing and accessing configuration data with minimal dependencies

Installation

go get github.com/chen-keinan/go-simple-config

Supported configuration files:

  • yaml
  • json
  • properties
  • environment variables
  • ini

Usage

json config example:

{
  "SERVER": {
    "host": "127.0.0.1",
    "port": "8080"
  }

yaml config example:

---
SERVER:
  host: 127.0.0.1
  port: '8080'

properties config example:

SERVER.host=127.0.0.1
SERVER.port=8080

env. variable config example:

export SERVER_HOST="127.0.0.1"
export SERVER_PORT="8080"

Full example :

package main

import (
	"fmt"
	"github.com/chen-keinan/go-simple-config/simple"
	"os"
)

func main() {
	c := simple.New()
	err := c.Load("config.json")

	if err != nil {
		fmt.Print(err.Error())
		os.Exit(1)
	}
	fmt.Print(c.GetStringValue("SERVER.host"))
}