feat: scaffold files service
This commit is contained in:
62
internal/config/config.go
Normal file
62
internal/config/config.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
ServerPort string
|
||||
DatabaseURL string
|
||||
MigrationsDir string
|
||||
InternalAPIKey string
|
||||
PublicBaseURL string
|
||||
|
||||
MinIOEndpoint string
|
||||
MinIOAccessKey string
|
||||
MinIOSecretKey string
|
||||
MinIOBucket string
|
||||
MinIOUseSSL bool
|
||||
|
||||
PodName string
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
return &Config{
|
||||
ServerPort: envStr("SERVER_PORT", "3001"),
|
||||
DatabaseURL: envStr("DATABASE_URL", "postgres://files:files@localhost:5432/files?sslmode=disable"),
|
||||
MigrationsDir: envStr("MIGRATIONS_DIR", "/migrations"),
|
||||
InternalAPIKey: envStr("INTERNAL_API_KEY", envStr("PORTAL_INTERNAL_API_KEY", "")),
|
||||
PublicBaseURL: envStr("PUBLIC_BASE_URL", "https://portal.estateliga.work"),
|
||||
MinIOEndpoint: envStr("MINIO_ENDPOINT", ""),
|
||||
MinIOAccessKey: envStr("MINIO_ACCESS_KEY", ""),
|
||||
MinIOSecretKey: envStr("MINIO_SECRET_KEY", ""),
|
||||
MinIOBucket: envStr("MINIO_BUCKET", "portal-files"),
|
||||
MinIOUseSSL: envBool("MINIO_USE_SSL", false),
|
||||
PodName: envStr("POD_NAME", hostname()),
|
||||
}
|
||||
}
|
||||
|
||||
func envBool(key string, def bool) bool {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
if b, err := strconv.ParseBool(v); err == nil {
|
||||
return b
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func envStr(key, def string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return def
|
||||
}
|
||||
|
||||
func hostname() string {
|
||||
h, err := os.Hostname()
|
||||
if err != nil {
|
||||
return "unknown"
|
||||
}
|
||||
return h
|
||||
}
|
||||
Reference in New Issue
Block a user