-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
54 lines (44 loc) · 1.34 KB
/
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
45
46
47
48
49
50
51
52
53
54
package hook
// Config handles discord bot connection configuration and logrus levels.
type Config struct {
// Disabled can disable hook form configuration file.
Disabled bool `json:"disabled" yaml:"disabled"`
// Token is bot token from discord developers applications.
Token string `json:"token" yaml:"token"`
// ChannelID is id of discord channel to log hooks.
ChannelID string `json:"channel_id" yaml:"channel_id"`
// Format specifies formatter to discord message.
// Supported formats: text, json, embed.
Format string `json:"format" yaml:"format"`
// MinLevel is the minimum priority level to enable logging.
MinLevel string `json:"min_level" yaml:"min_level"`
// Levels is a list of levels to enable logging. Intersects with MinLevel.
Levels []string `json:"levels" yaml:"levels"`
}
// NewDefaultConfig returns default configuration for hook.
func NewDefaultConfig(token string, channelID string) *Config {
return &Config{
Disabled: false,
Token: token,
ChannelID: channelID,
MinLevel: "info",
Format: EmbedFormatterCode,
Levels: []string{
"error",
"warning",
"info",
"trace",
},
}
}
// Validate checks config for required fields.
func (cfg *Config) Validate() error {
// Do not validate disabled hook.
if cfg.Disabled {
return nil
}
if cfg.ChannelID == "" {
return ErrEmptyChannelID
}
return nil
}