hongbo-miao/hongbomiao.com

View on GitHub
api-go/internal/decision_logger/utils/get_config.go

Summary

Maintainability
A
0 mins
Test Coverage
package utils

import (
    "github.com/joho/godotenv"
    "os"
)

type Config struct {
    AppEnv string
    Port   string
}

func GetConfig() *Config {
    path := "config/decision_logger/"

    appEnv := os.Getenv("APP_ENV")
    if appEnv == "" {
        appEnv = "development"
    }

    _ = godotenv.Load(path + ".env." + appEnv + ".local")
    _ = godotenv.Load(path + ".env." + appEnv)

    return &Config{
        AppEnv: appEnv,
        Port:   os.Getenv("PORT"),
    }
}