config: Add cache type
This commit is contained in:
parent
d35b77fbc9
commit
652d46d972
2 changed files with 25 additions and 0 deletions
|
@ -96,6 +96,8 @@ alertmanager {
|
||||||
# When the alert-mode is set to single, ntfy-alertmanager will cache each single alert
|
# When the alert-mode is set to single, ntfy-alertmanager will cache each single alert
|
||||||
# to avoid sending recurrences.
|
# to avoid sending recurrences.
|
||||||
cache {
|
cache {
|
||||||
|
# The type of cache that will be used (default is memory).
|
||||||
|
type memory
|
||||||
# How long messages stay in the cache for
|
# How long messages stay in the cache for
|
||||||
duration 24h
|
duration 24h
|
||||||
# Interval in which the cache is cleaned up
|
# Interval in which the cache is cleaned up
|
||||||
|
|
23
config.go
23
config.go
|
@ -16,6 +16,12 @@ const (
|
||||||
multi
|
multi
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type cacheType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
memory cacheType = iota
|
||||||
|
)
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
BaseURL string
|
BaseURL string
|
||||||
HTTPAddress string
|
HTTPAddress string
|
||||||
|
@ -49,6 +55,7 @@ type labelConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type cacheConfig struct {
|
type cacheConfig struct {
|
||||||
|
Type cacheType
|
||||||
CleanupInterval time.Duration
|
CleanupInterval time.Duration
|
||||||
Duration time.Duration
|
Duration time.Duration
|
||||||
}
|
}
|
||||||
|
@ -77,6 +84,7 @@ func readConfig(path string) (*config, error) {
|
||||||
config.LogLevel = "info"
|
config.LogLevel = "info"
|
||||||
config.alertMode = single
|
config.alertMode = single
|
||||||
|
|
||||||
|
config.cache.Type = memory
|
||||||
config.cache.CleanupInterval = time.Hour
|
config.cache.CleanupInterval = time.Hour
|
||||||
config.cache.Duration = time.Hour * 24
|
config.cache.Duration = time.Hour * 24
|
||||||
|
|
||||||
|
@ -238,6 +246,21 @@ func readConfig(path string) (*config, error) {
|
||||||
cacheDir := cfg.Get("cache")
|
cacheDir := cfg.Get("cache")
|
||||||
|
|
||||||
if cacheDir != nil {
|
if cacheDir != nil {
|
||||||
|
d = cacheDir.Children.Get("type")
|
||||||
|
if d != nil {
|
||||||
|
var cacheType string
|
||||||
|
if err := d.ParseParams(&cacheType); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch strings.ToLower(cacheType) {
|
||||||
|
case "memory":
|
||||||
|
config.cache.Type = memory
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("cache: illegal type %q", cacheType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var durationString string
|
var durationString string
|
||||||
d = cacheDir.Children.Get("duration")
|
d = cacheDir.Children.Get("duration")
|
||||||
if d != nil {
|
if d != nil {
|
||||||
|
|
Loading…
Reference in a new issue