2021-10-24 03:29:45 +02:00
|
|
|
// Package config provides the main configuration
|
|
|
|
package config
|
|
|
|
|
2021-10-24 04:49:50 +02:00
|
|
|
import (
|
|
|
|
"golang.org/x/time/rate"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Defines default config settings
|
2021-10-24 03:29:45 +02:00
|
|
|
const (
|
2021-10-29 19:58:14 +02:00
|
|
|
DefaultListenHTTP = ":80"
|
|
|
|
DefaultMessageBufferDuration = 12 * time.Hour
|
|
|
|
DefaultKeepaliveInterval = 30 * time.Second
|
|
|
|
DefaultManagerInterval = time.Minute
|
2021-10-24 04:49:50 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Defines the max number of requests, here:
|
|
|
|
// 50 requests bucket, replenished at a rate of 1 per second
|
|
|
|
var (
|
2021-11-01 20:21:38 +01:00
|
|
|
defaultRequestLimit = rate.Every(time.Second)
|
|
|
|
defaultRequestLimitBurst = 50
|
|
|
|
defaultSubscriptionLimit = 30 // per visitor
|
2021-10-24 03:29:45 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config is the main config struct for the application. Use New to instantiate a default config struct.
|
|
|
|
type Config struct {
|
2021-10-29 19:58:14 +02:00
|
|
|
ListenHTTP string
|
|
|
|
FirebaseKeyFile string
|
|
|
|
MessageBufferDuration time.Duration
|
|
|
|
KeepaliveInterval time.Duration
|
|
|
|
ManagerInterval time.Duration
|
2021-11-01 20:21:38 +01:00
|
|
|
RequestLimit rate.Limit
|
|
|
|
RequestLimitBurst int
|
|
|
|
SubscriptionLimit int
|
2021-10-24 03:29:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// New instantiates a default new config
|
|
|
|
func New(listenHTTP string) *Config {
|
|
|
|
return &Config{
|
2021-10-29 19:58:14 +02:00
|
|
|
ListenHTTP: listenHTTP,
|
|
|
|
FirebaseKeyFile: "",
|
|
|
|
MessageBufferDuration: DefaultMessageBufferDuration,
|
|
|
|
KeepaliveInterval: DefaultKeepaliveInterval,
|
|
|
|
ManagerInterval: DefaultManagerInterval,
|
2021-11-01 20:21:38 +01:00
|
|
|
RequestLimit: defaultRequestLimit,
|
|
|
|
RequestLimitBurst: defaultRequestLimitBurst,
|
|
|
|
SubscriptionLimit: defaultSubscriptionLimit,
|
2021-10-24 03:29:45 +02:00
|
|
|
}
|
|
|
|
}
|