Skip to content

lbrun25/fenv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fenv

This is a Go library to parse environment variables in a file.

Install

go get github.com/lbrun25/fenv

Example

Can parse any environment variable in a file

server:
  hostname: ${HOSTNAME}
  port: ${PORT}

and returns []byte

server:
  hostname: localhost
  port: 8080

Usage

package 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)
	}
}

About

Golang library to parse environment variables in files

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages