config.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package config
  5. import (
  6. "os"
  7. "strconv"
  8. )
  9. // Default config parameters values
  10. const (
  11. DefaultBaseURL = "http://localhost"
  12. DefaultDatabaseURL = "postgres://postgres:postgres@localhost/miniflux2?sslmode=disable"
  13. DefaultWorkerPoolSize = 5
  14. DefaultPollingFrequency = 60
  15. DefaultBatchSize = 10
  16. DefaultDatabaseMaxConns = 20
  17. DefaultListenAddr = "127.0.0.1:8080"
  18. DefaultCertFile = ""
  19. DefaultKeyFile = ""
  20. DefaultCertDomain = ""
  21. DefaultCertCache = "/tmp/cert_cache"
  22. DefaultSessionCleanupFrequency = 24
  23. )
  24. // Config manages configuration parameters.
  25. type Config struct {
  26. IsHTTPS bool
  27. }
  28. // Get returns a config parameter value.
  29. func (c *Config) Get(key, fallback string) string {
  30. value := os.Getenv(key)
  31. if value == "" {
  32. return fallback
  33. }
  34. return value
  35. }
  36. // GetInt returns a config parameter as integer.
  37. func (c *Config) GetInt(key string, fallback int) int {
  38. value := os.Getenv(key)
  39. if value == "" {
  40. return fallback
  41. }
  42. v, _ := strconv.Atoi(value)
  43. return v
  44. }
  45. // NewConfig returns a new Config.
  46. func NewConfig() *Config {
  47. return &Config{IsHTTPS: os.Getenv("HTTPS") != ""}
  48. }