-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
49 lines (43 loc) · 1.52 KB
/
config.go
File metadata and controls
49 lines (43 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"github.com/charmbracelet/log"
"github.com/hashicorp/hcl/v2/hclsimple"
)
type Config struct {
Owner string `hcl:"feed_owner"`
Base string `hcl:"feed_base"`
Feeds []*Feed `hcl:"feed,block"`
Debug bool `hcl:"debug,optional"`
Analyzers []*AnalyzerConfig `hcl:"analyzer,block"`
}
type PublishConfig struct {
ServiceHost string `hcl:"service_host,label"`
ServiceIcon string `hcl:"service_icon,optional"`
ServiceShortName string `hcl:"service_short_name,optional"`
ServiceHumanName string `hcl:"service_human_name,optional"`
ServiceDescription string `hcl:"service_description,optional"`
ServiceDID string `hcl:"service_did"`
}
type AnalyzerConfig struct {
ID string `hcl:"id,label"`
Triggers []string `hcl:"triggers,optional"`
Threshold float64 `hcl:"threshold,optional"`
Patterns map[string]float64 `hcl:"patterns"`
AnyTrigger bool `hcl:"any_trigger,optional"`
}
func readConfig(filename string) (*Config, error) {
var config = &Config{}
err := hclsimple.DecodeFile(filename, nil, config)
if err != nil {
log.Error("Failed to load configuration", "error", err)
return nil, err
}
log.Debug("Configuration is %#v", config)
for _, fc := range config.Feeds {
fc.filters = map[string]*TextAnalyzer{}
for _, ac := range config.Analyzers {
fc.filters[ac.ID] = NewTextAnalyzer(ac.Triggers, ac.Patterns, ac.Threshold, ac.AnyTrigger)
}
}
return config, nil
}