config.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. KeepaliveInterval time.Duration
  25. ManagerInterval time.Duration
  26. }
  27. // New instantiates a default new config
  28. func New(listenHTTP string) *Config {
  29. return &Config{
  30. ListenHTTP: listenHTTP,
  31. Limit: defaultLimit,
  32. LimitBurst: defaultLimitBurst,
  33. KeepaliveInterval: DefaultKeepaliveInterval,
  34. ManagerInterval: defaultManagerInterval,
  35. }
  36. }