-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
44 lines (35 loc) · 864 Bytes
/
config.go
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
package hayden
import (
"context"
"encoding/json"
"go.uber.org/zap"
)
type Config struct {
Log *zap.SugaredLogger `json:"-"`
DefaultHook string `json:"default-hook"`
DefaultPeriod int `json:"default-period"`
}
type ConfigFile struct {
Config *Config `json:"config"`
Targets []*Target `json:"targets"`
}
func ParseConfigFile(stream []byte) (*ConfigFile, error) {
var cf ConfigFile
if err := json.Unmarshal(stream, &cf); err != nil {
return nil, err
}
return &cf, nil
}
func (cf *ConfigFile) ScrapeTargets(ctx context.Context) error {
for _, t := range cf.Targets {
match, err := t.Scan(ctx, cf.Config)
if err != nil {
cf.Config.Log.Errorw("error on target", "target", t, zap.Error(err))
continue
}
if match {
cf.Config.Log.Infow("success on scan", "target", t)
}
}
return nil
}