new file: .env copy
new file: internal/config/config.go add configs .env file and config loader
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
# DB environment variabels
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
DB_USER=postgres
|
||||
DB_PASSWORD=postgres
|
||||
DB_NAME=mydb
|
||||
APP_PORT=8080
|
||||
JWT_SECRET=secret
|
||||
UPLOAD_PATH=./storage/uploads
|
||||
ENVIRONMENT=development
|
||||
LOG_LEVEL=debug
|
||||
API_ES_APP_PORT=8088
|
||||
@@ -0,0 +1,42 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DBHost string
|
||||
DBPort string
|
||||
DBUser string
|
||||
DBPassword string
|
||||
DBName string
|
||||
JWTSecret string
|
||||
ServerPort string
|
||||
UploadPath string
|
||||
LogLevel string
|
||||
Environment string
|
||||
AppPort string
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
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", "mydb"),
|
||||
JWTSecret: getEnv("JWT_SECRET", "secret"),
|
||||
ServerPort: getEnv("SERVER_PORT", "8080"),
|
||||
UploadPath: getEnv("UPLOAD_PATH", "./storage/uploads"),
|
||||
LogLevel: getEnv("LOG_LEVEL", "debug"),
|
||||
Environment: getEnv("ENVIRONMENT", "development"),
|
||||
AppPort: getEnv("APP_PORT", "8088"),
|
||||
}
|
||||
}
|
||||
|
||||
func getEnv(key, defaultValue string) string {
|
||||
if value := os.Getenv(key); value != "" {
|
||||
return value
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
Reference in New Issue
Block a user