first commit
This commit is contained in:
48
internal/config/config.go
Normal file
48
internal/config/config.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DBHost string
|
||||
DBPort string
|
||||
DBUser string
|
||||
DBPassword string
|
||||
DBName string
|
||||
DBSSLMode string
|
||||
Topics []string
|
||||
LogDebug bool
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
_ = godotenv.Load()
|
||||
|
||||
return &Config{
|
||||
DBHost: getEnv("DB_HOST", "localhost"),
|
||||
DBPort: getEnv("DB_PORT", "5432"),
|
||||
DBUser: getEnv("DB_USER", "postgres"),
|
||||
DBPassword: getEnv("DB_PASSWORD", "postgres"),
|
||||
DBName: getEnv("DB_NAME", "middleware"),
|
||||
DBSSLMode: getEnv("DB_SSLMODE", "disable"),
|
||||
Topics: strings.Split(getEnv("WATERMILL_TOPICS", "example_topic"), ","),
|
||||
LogDebug: getEnv("LOG_DEBUG", "false") == "true",
|
||||
}
|
||||
}
|
||||
|
||||
func getEnv(key, def string) string {
|
||||
if val, ok := os.LookupEnv(key); ok {
|
||||
return val
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func Must(err error) {
|
||||
if err != nil {
|
||||
log.Fatalf("❌ %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user