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

39 lines
1.1 KiB
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
2021-06-08 21:26:14 +03:00
Exchange string // Rabbit exchange name
QueueBack string // queue name
2021-06-01 14:26:02 +03:00
QueueDB string
2021-06-08 21:26:14 +03:00
KeyFront string // routing key name
2021-06-01 14:26:02 +03:00
KeyBack string
KeyDB string
}
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"),
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
}