config.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Package config provides the main configuration
  2. package config
  3. import (
  4. "golang.org/x/time/rate"
  5. "time"
  6. )
  7. // Defines default config settings
  8. const (
  9. DefaultListenHTTP = ":80"
  10. DefaultKeepaliveInterval = 30 * time.Second
  11. defaultManagerInterval = time.Minute
  12. )
  13. // Defines the max number of requests, here:
  14. // 50 requests bucket, replenished at a rate of 1 per second
  15. var (
  16. defaultLimit = rate.Every(time.Second)
  17. defaultLimitBurst = 50
  18. )
  19. // Config is the main config struct for the application. Use New to instantiate a default config struct.
  20. type Config struct {
  21. ListenHTTP string
  22. Limit rate.Limit
  23. LimitBurst int
  24. FirebaseKeyFile string
  25. KeepaliveInterval time.Duration
  26. ManagerInterval time.Duration
  27. }
  28. // New instantiates a default new config
  29. func New(listenHTTP string) *Config {
  30. return &Config{
  31. ListenHTTP: listenHTTP,
  32. Limit: defaultLimit,
  33. LimitBurst: defaultLimitBurst,
  34. FirebaseKeyFile: "",
  35. KeepaliveInterval: DefaultKeepaliveInterval,
  36. ManagerInterval: defaultManagerInterval,
  37. }
  38. }