This is a Go library to parse environment variables in a file.
go get github.com/lbrun25/fenvCan parse any environment variable in a file
server:
hostname: ${HOSTNAME}
port: ${PORT}and returns []byte
server:
hostname: localhost
port: 8080package main
import (
"bytes"
"log"
"github.com/lbrun25/fenv"
"github.com/spf13/viper"
)
func main() {
f := fenv.OS()
// Parse the file
newContent, err := f.Parse("./config.yml")
if err != nil {
log.Fatal(err)
}
// Use parsed configuration with viper for example
viper.SetConfigName("config")
viper.SetConfigType("yml")
viper.AddConfigPath(".")
err = viper.ReadConfig(bytes.NewBuffer(newContent))
if err != nil {
log.Fatal(err)
}
}