config.go 891 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. defaultManagerInterval = time.Minute
  11. )
  12. // Defines the max number of requests, here:
  13. // 50 requests bucket, replenished at a rate of 1 per second
  14. var (
  15. defaultLimit = rate.Every(time.Second)
  16. defaultLimitBurst = 50
  17. )
  18. // Config is the main config struct for the application. Use New to instantiate a default config struct.
  19. type Config struct {
  20. ListenHTTP string
  21. Limit rate.Limit
  22. LimitBurst int
  23. ManagerInterval time.Duration
  24. }
  25. // New instantiates a default new config
  26. func New(listenHTTP string) *Config {
  27. return &Config{
  28. ListenHTTP: listenHTTP,
  29. Limit: defaultLimit,
  30. LimitBurst: defaultLimitBurst,
  31. ManagerInterval: defaultManagerInterval,
  32. }
  33. }