ntfy/config/config.go

57 lines
1.8 KiB
Go
Raw Normal View History

// Package config provides the main configuration
package config
2021-10-24 02:49:50 +00:00
import (
"golang.org/x/time/rate"
"time"
)
// Defines default config settings
const (
2021-11-03 15:33:34 +00:00
DefaultListenHTTP = ":80"
DefaultCacheDuration = 12 * time.Hour
DefaultKeepaliveInterval = 30 * time.Second
DefaultManagerInterval = time.Minute
2021-10-24 02:49:50 +00:00
)
2021-11-01 20:39:40 +00:00
// Defines all the limits
// - request limit: max number of PUT/GET/.. requests (here: 50 requests bucket, replenished at a rate of 1 per second)
// - global topic limit: max number of topics overall
// - subscription limit: max number of subscriptions (active HTTP connections) per per-visitor/IP
2021-10-24 02:49:50 +00:00
var (
2021-11-01 20:39:40 +00:00
defaultGlobalTopicLimit = 5000
defaultVisitorRequestLimit = rate.Every(time.Second)
defaultVisitorRequestLimitBurst = 50
defaultVisitorSubscriptionLimit = 30
)
// Config is the main config struct for the application. Use New to instantiate a default config struct.
type Config struct {
2021-11-01 20:39:40 +00:00
ListenHTTP string
FirebaseKeyFile string
2021-11-03 15:33:34 +00:00
CacheFile string
CacheDuration time.Duration
2021-11-01 20:39:40 +00:00
KeepaliveInterval time.Duration
ManagerInterval time.Duration
GlobalTopicLimit int
VisitorRequestLimit rate.Limit
VisitorRequestLimitBurst int
VisitorSubscriptionLimit int
}
// New instantiates a default new config
func New(listenHTTP string) *Config {
return &Config{
2021-11-01 20:39:40 +00:00
ListenHTTP: listenHTTP,
FirebaseKeyFile: "",
2021-11-03 15:33:34 +00:00
CacheFile: "",
CacheDuration: DefaultCacheDuration,
2021-11-01 20:39:40 +00:00
KeepaliveInterval: DefaultKeepaliveInterval,
ManagerInterval: DefaultManagerInterval,
GlobalTopicLimit: defaultGlobalTopicLimit,
VisitorRequestLimit: defaultVisitorRequestLimit,
VisitorRequestLimitBurst: defaultVisitorRequestLimitBurst,
VisitorSubscriptionLimit: defaultVisitorSubscriptionLimit,
}
}