You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
1.0 KiB

  1. package config
  2. import "os"
  3. type Config struct {
  4. HTTPAddr string
  5. WSAddr string
  6. MQTTHost string
  7. MQTTUser string
  8. MQTTPass string
  9. MQTTClientID string
  10. KafkaURL string
  11. DBHost string
  12. DBUser string
  13. DBPass string
  14. DBName string
  15. }
  16. // getEnv returns env var value or a default if not set.
  17. func getEnv(key, def string) string {
  18. if v := os.Getenv(key); v != "" {
  19. return v
  20. }
  21. return def
  22. }
  23. func Load() *Config {
  24. return &Config{
  25. HTTPAddr: getEnv("HTTP_HOST_PATH", "0.0.0.0:1902"),
  26. WSAddr: getEnv("HTTPWS_HOST_PATH", "0.0.0.0:8088"),
  27. MQTTHost: getEnv("MQTT_HOST", "192.168.1.101"),
  28. MQTTUser: getEnv("MQTT_USERNAME", "user"),
  29. MQTTPass: getEnv("MQTT_PASSWORD", "pass"),
  30. MQTTClientID: getEnv("MQTT_CLIENT_ID", "presence-detector"),
  31. KafkaURL: getEnv("KAFKA_URL", "127.0.0.1:9092"),
  32. DBHost: getEnv("DBHost", "127.0.0.1"),
  33. DBUser: getEnv("DBUser", "postgres"),
  34. DBPass: getEnv("DBPass", "postgres"),
  35. DBName: getEnv("DBName", "go_crud_db"),
  36. }
  37. }