Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

53 Zeilen
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. QCBaseURL string
  12. QCToken string
  13. PollIntervalSeconds int
  14. PollTimeoutSeconds int
  15. PollMaxConcurrent int
  16. }
  17. func Load() Config {
  18. return Config{
  19. HTTPAddr: getenv("HTTP_ADDR", ":8080"),
  20. DBDriver: getenv("DB_DRIVER", "sqlite"),
  21. DBURL: getenv("DB_URL", "data/qctextbuilder.db"),
  22. AppSecret: os.Getenv("APP_SECRET"),
  23. QCBaseURL: getenv("QC_BASE_URL", "https://qc-api.yggdrasil.dev-mono.net/api/v1"),
  24. QCToken: os.Getenv("QC_TOKEN"),
  25. PollIntervalSeconds: getenvInt("POLL_INTERVAL_SECONDS", 5),
  26. PollTimeoutSeconds: getenvInt("POLL_TIMEOUT_SECONDS", 300),
  27. PollMaxConcurrent: getenvInt("POLL_MAX_CONCURRENT", 4),
  28. }
  29. }
  30. func getenv(key, fallback string) string {
  31. v := os.Getenv(key)
  32. if v == "" {
  33. return fallback
  34. }
  35. return v
  36. }
  37. func getenvInt(key string, fallback int) int {
  38. v := os.Getenv(key)
  39. if v == "" {
  40. return fallback
  41. }
  42. n, err := strconv.Atoi(v)
  43. if err != nil {
  44. return fallback
  45. }
  46. return n
  47. }