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

50 lines
1.3 KiB
Go
Raw Permalink Normal View History

2021-06-01 14:26:02 +03:00
package config
import "os"
2021-06-12 15:52:52 +03:00
// Config stores configuration
2021-06-01 14:26:02 +03:00
type Config struct {
2021-10-05 16:10:14 +03:00
// Connection strings
2021-06-01 14:26:02 +03:00
ServerAddr string
PostgresURL string
RabbitURL string
2021-10-05 16:10:14 +03:00
RedisURL string
// Rabbit exchange name
Exchange string
// Queue names
QueueBack string
QueueDB string
QueueCache string
// Routing key names
KeyFront string
KeyBack string
KeyDB string
KeyCache string
2021-06-01 14:26:02 +03:00
}
2021-06-08 21:26:14 +03:00
// New returns configuration variables from the environment.
// These are passed by Docker from the .env file.
2021-06-01 14:26:02 +03:00
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"),
2021-10-05 16:10:14 +03:00
RedisURL: getEnv("REDIS_URL", "localhost:6379"),
2021-06-01 14:26:02 +03:00
Exchange: getEnv("EXCHANGE", "main_exchange"),
QueueBack: getEnv("QUEUE_BACK", "backend_queue"),
QueueDB: getEnv("QUEUE_DB", "db_queue"),
2021-10-05 16:10:14 +03:00
QueueCache: getEnv("QUEUE_CACHE", "cache_queue"),
2021-06-01 14:26:02 +03:00
KeyFront: getEnv("KEY_FRONT", "frontend_key"),
KeyBack: getEnv("KEY_BACK", "backend_key"),
KeyDB: getEnv("KEY_DB", "db_key"),
2021-10-05 16:10:14 +03:00
KeyCache: getEnv("KEY_CACHE", "cache_key"),
2021-06-01 14:26:02 +03:00
}
}
func getEnv(key string, defaultVal string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return defaultVal
}