Skip to content

frozzare/go-config

Repository files navigation

Config Build Status GoDoc Go Report Card

Go package for dealing with configuration files, has built in support for environment variables and JSON files and support for YAML and Toml via plugins.

Installation

go get github.com/frozzare/go-config

Example

package main

import (
	"io"
	"net/http"

	"github.com/frozzare/go-config"

	_ "github.com/frozzare/go-config/plugins/yaml"
)

func main() {
	// Use read and watch file + env as middlewares.
	config.Use(config.NewFromFile("config.yml", true))
	config.Use(config.NewEnv())

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		v, _ := config.String("name")
		io.WriteString(w, v)
	})

	http.ListenAndServe(":8899", nil)
}

License

MIT © Fredrik Forsmo