Skip to content

Go package to read, parse and store environment files, strings and variables.

Notifications You must be signed in to change notification settings

theTardigrade/golang-envStore

Repository files navigation

golang-envStore

Store your environment variables from multiple sources (files, strings, JSON and the operating system) in one data structure, allowing easy access (potentially concurrent) from within your program.

Example

package main

import (
	envStore "github.com/theTardigrade/golang-envStore"
)

func main() {
	env, err := envStore.New(&envStore.Config{
		FromFilePaths: []string{"data1.env", "data2.env"},
		FromStrings: []string{"x=128\ny=test\nz=/bin/bash"},
		FromJSONSlices: [][]byte{[]byte(`{"key":"value","key2":"value2"}`)},
		FromSystem: true,
		UseMutex: true,
		IgnoreEmptyLines: true,
	})
	if err != nil {
		panic(err)
	}

	env.Iterate(func(key, value string) {
		fmt.Printf("%v :: %v\n", key, value)
	})
}