api/config/config.go

94 lines
2 KiB
Go
Raw Permalink Normal View History

2025-07-06 17:59:18 +03:00
package config
2025-09-29 21:49:25 +03:00
import "strings"
2025-07-06 17:59:18 +03:00
type Config struct {
2025-10-15 19:45:49 +03:00
AppConf AppConfig
DBConf DatabaseConfig
JWTConf JWTConfig
GrpcConf GrpcConfig
MediaConf MediaConfig
2025-07-06 17:59:18 +03:00
}
type AppConfig struct {
2025-09-29 21:49:25 +03:00
Host string
Port string
LogLvl string
ApiPrefix string
GinMode string
AllowedOrigins []string
2025-07-06 17:59:18 +03:00
}
type DatabaseConfig struct {
Host string
Port string
User string
Password string
SSLMode string
DBName string
LogLevel string
}
2025-07-06 22:25:10 +03:00
type JWTConfig struct {
Secret string
Issuer string
AccessExpire string
RefreshExpire string
}
2025-10-01 19:32:56 +03:00
type GrpcConfig struct {
GrpcServerPort string
GrpcClientPort string
}
2025-10-15 19:45:49 +03:00
type MediaConfig struct {
Host string
Port string
User string
Password string
2025-10-16 15:41:52 +03:00
Secure string
2025-10-15 19:45:49 +03:00
}
2025-07-06 17:59:18 +03:00
func NewConfig() *Config {
return &Config{
AppConf: AppConfig{
2025-09-29 21:49:25 +03:00
Host: getEnv("APP_HOST", ""),
Port: getEnv("APP_PORT", ""),
LogLvl: getEnv("APP_LOGLVL", ""),
ApiPrefix: getEnv("APP_API_PREFIX", ""),
GinMode: getEnv("APP_GIN_MODE", ""),
AllowedOrigins: strings.Split(getEnv("APP_ALLOWED_ORIGINS", ""), ","),
2025-07-06 17:59:18 +03:00
},
DBConf: DatabaseConfig{
Host: getEnv("DB_HOST", ""),
Port: getEnv("DB_PORT", ""),
User: getEnv("DB_USER", ""),
Password: getEnv("DB_PASSWORD", ""),
SSLMode: getEnv("DB_SSLMODE", ""),
DBName: getEnv("DB_NAME", ""),
LogLevel: getEnv("DB_LOGLEVEL", ""),
},
2025-07-06 22:25:10 +03:00
JWTConf: JWTConfig{
Secret: getEnv("JWT_SECRET", ""),
Issuer: getEnv("JWT_ISSUER", ""),
AccessExpire: getEnv("JWT_ACCESS_EXPIRE", ""),
RefreshExpire: getEnv("JWT_REFRESH_EXPIRE", ""),
},
2025-10-01 19:32:56 +03:00
GrpcConf: GrpcConfig{
GrpcServerPort: getEnv("GRPC_SERVER_PORT", ""),
GrpcClientPort: getEnv("GRPC_CLIENT_PORT", ""),
},
2025-10-15 19:45:49 +03:00
MediaConf: MediaConfig{
Host: getEnv("MEDIA_STORAGE_HOST", ""),
Port: getEnv("MEDIA_STORAGE_PORT", ""),
User: getEnv("MEDIA_STORAGE_USER", ""),
Password: getEnv("MEDIA_STORAGE_PASSWORD", ""),
2025-10-16 15:41:52 +03:00
Secure: getEnv("MEDIA_STORAGE_SECURE", ""),
2025-10-15 19:45:49 +03:00
},
2025-07-06 17:59:18 +03:00
}
}