1
0
mirror of https://github.com/ebosas/microservices.git synced 2025-06-06 22:16:11 +02:00
microservices/config/config.go

38 lines
945 B
Go
Raw Normal View History

2021-06-01 14:26:02 +03:00
package config
import "os"
type Config struct {
ServerAddr string
PostgresURL string
RabbitURL string
Exchange string
QueueBack string
QueueDB string
KeyFront string
KeyBack string
KeyDB string
}
func New() *Config {
return &Config{
ServerAddr: getEnv("SERVER_ADDR", "localhost:8080"),
2021-06-02 14:43:57 +03:00
PostgresURL: getEnv("POSTGRES_URL", "postgres://postgres:demopsw@localhost:5432/microservices"),
2021-06-01 14:26:02 +03:00
RabbitURL: getEnv("RABBIT_URL", "amqp://guest:guest@localhost:5672"),
Exchange: getEnv("EXCHANGE", "main_exchange"),
QueueBack: getEnv("QUEUE_BACK", "backend_queue"),
QueueDB: getEnv("QUEUE_DB", "db_queue"),
KeyFront: getEnv("KEY_FRONT", "frontend_key"),
KeyBack: getEnv("KEY_BACK", "backend_key"),
KeyDB: getEnv("KEY_DB", "db_key"),
}
}
func getEnv(key string, defaultVal string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return defaultVal
}