main.go 391 B

123456789101112131415161718192021222324252627
  1. package config
  2. import (
  3. "os"
  4. "github.com/joho/godotenv"
  5. )
  6. func getEnvFile() (string, bool) {
  7. goEnv, _ := os.LookupEnv("GO_ENV")
  8. switch goEnv {
  9. case "test":
  10. return "test.env", true
  11. case "development":
  12. return ".env", true
  13. default:
  14. return "", false
  15. }
  16. }
  17. func LoadEnv() {
  18. envFile, loadEnvFile := getEnvFile()
  19. if loadEnvFile {
  20. godotenv.Load(envFile)
  21. }
  22. }