-
Notifications
You must be signed in to change notification settings - Fork 14
/
library.go
47 lines (38 loc) · 1.25 KB
/
library.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
45
46
47
package config
import (
"encoding/base64"
"github.com/anz-bank/sysl-go/common"
"github.com/anz-bank/sysl-go/validator"
"github.com/sirupsen/logrus"
)
// LibraryConfig struct
type LibraryConfig struct {
Log LogConfig `yaml:"log"`
Profiling bool `yaml:"profiling"`
}
// LogConfig struct
type LogConfig struct {
Format string `yaml:"format" validate:"nonnil,oneof=color json text"`
Splunk *SplunkConfig `yaml:"splunk"`
Level logrus.Level `yaml:"level" validate:"nonnil"`
ReportCaller bool `yaml:"caller" mapstructure:"caller"`
}
// SplunkConfig struct
type SplunkConfig struct {
TokenBase64 common.SensitiveString `yaml:"tokenBase64" validate:"nonnil,base64"`
Index string `yaml:"index" validate:"nonnil"`
Target string `yaml:"target" validate:"nonnil,url"`
Source string `yaml:"source" validate:"nonnil"`
SourceType string `yaml:"sourceType" validate:"nonnil"`
}
func (s *SplunkConfig) Token() string {
b, _ := base64.StdEncoding.DecodeString(s.TokenBase64.Value())
return string(b)
}
func (c *LibraryConfig) Validate() error {
// existing validation
if err := validator.Validate(c); err != nil {
return err
}
return nil
}