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.
go get github.com/frozzare/go-config
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)
}
MIT © Fredrik Forsmo