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.

55 line
1.2KB

  1. package config
  2. import (
  3. "os"
  4. "strconv"
  5. )
  6. type Config struct {
  7. HTTPAddr string
  8. DBDriver string
  9. DBURL string
  10. AppSecret string
  11. LogLevel string
  12. QCBaseURL string
  13. QCToken string
  14. PollIntervalSeconds int
  15. PollTimeoutSeconds int
  16. PollMaxConcurrent int
  17. }
  18. func Load() Config {
  19. return Config{
  20. HTTPAddr: getenv("HTTP_ADDR", ":8080"),
  21. DBDriver: getenv("DB_DRIVER", "sqlite"),
  22. DBURL: getenv("DB_URL", "data/qctextbuilder.db"),
  23. AppSecret: os.Getenv("APP_SECRET"),
  24. LogLevel: getenv("LOG_LEVEL", "info"),
  25. QCBaseURL: getenv("QC_BASE_URL", "https://qc-api.yggdrasil.dev-mono.net/api/v1"),
  26. QCToken: os.Getenv("QC_TOKEN"),
  27. PollIntervalSeconds: getenvInt("POLL_INTERVAL_SECONDS", 5),
  28. PollTimeoutSeconds: getenvInt("POLL_TIMEOUT_SECONDS", 300),
  29. PollMaxConcurrent: getenvInt("POLL_MAX_CONCURRENT", 4),
  30. }
  31. }
  32. func getenv(key, fallback string) string {
  33. v := os.Getenv(key)
  34. if v == "" {
  35. return fallback
  36. }
  37. return v
  38. }
  39. func getenvInt(key string, fallback int) int {
  40. v := os.Getenv(key)
  41. if v == "" {
  42. return fallback
  43. }
  44. n, err := strconv.Atoi(v)
  45. if err != nil {
  46. return fallback
  47. }
  48. return n
  49. }