config.go 624 Bytes
package domain

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

type Config struct {
	DatabaseUrl    string
	AppEnvironment string
	Port           string
}

func InitConfig() Config {
	environment := os.Getenv("APP_ENVIRONMENT")

	if environment == "" {
		environment = "production"
	}

	if environment == "development" {
		err := godotenv.Load()

		if err != nil {
			panic(err)
		}
	}

	port := os.Getenv("PORT")

	if port == "" {
		port = "8000"
	}

	log.Printf("Environment: %s", environment)

	return Config{
		DatabaseUrl:    os.Getenv("DATABASE_URL"),
		AppEnvironment: environment,
		Port:           port,
	}
}