All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 2m11s
42 lines
722 B
Go
42 lines
722 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
_ "github.com/joho/godotenv/autoload"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
DbUrl string
|
|
}
|
|
|
|
func Load() Config {
|
|
var dbUrl string
|
|
{
|
|
username := getEnv("DB_USERNAME")
|
|
password := getEnv("DB_PASSWORD")
|
|
name := getEnv("DB_NAME")
|
|
port := getEnv("DB_PORT")
|
|
host := getEnv("DB_HOST")
|
|
|
|
// postgres://admin:admin@localhost:5432/admin_db
|
|
dbUrl = fmt.Sprintf("postgres://%v:%v@%v:%v/%v?sslmode=disable", username, password, host, port, name)
|
|
}
|
|
|
|
cfg := Config{
|
|
DbUrl: dbUrl,
|
|
}
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
func getEnv(key string) string {
|
|
v := os.Getenv(key)
|
|
if v == "" {
|
|
log.Fatalf("The env variable %v is not defined and the applciation can not operate without\n", key)
|
|
}
|
|
return v
|
|
}
|