We have configuration file per deploy environment, as shown in below code:
configs/.dev.env
deploy_env=dev
configs/.env
deploy_env=local
main.go
package main
import (
"fmt"
"os"
"github.com/joho/godotenv"
)
func main() {
err := godotenv.Load("./configs/.env") // load
if err != nil {
fmt.Println("unable to load")
}
err = godotenv.Load("./configs/.dev.env") // expecting to override configuration
if err != nil {
fmt.Println("unable to load")
}
fmt.Println(os.Getenv("deploy_env")) // Got output as: local
// Expecting output: dev
}
How to override configuration? expecting deploy_env
to set as dev
?
CodePudding user response:
Use Overload
instead of Load