go get github.com/prongbang/goenv
DB_USER=root
DB_PASS=1234
import (
"fmt"
"os"
_ "github.com/prongbang/goenv"
)
func main() {
user := os.Getenv("DB_USER")
pass := os.Getenv("DB_PASS")
fmt.Println("user:", user)
fmt.Println("pass:", pass)
}
.testenv
DB_USER=root
DB_PASS=1234
Used
import (
"fmt"
"os"
"github.com/prongbang/goenv"
)
func main() {
err := goenv.LoadEnv(".testenv")
dbUser := os.Getenv("DB_USER")
dbPass := os.Getenv("DB_PASS")
}