M config.go => config.go +10 -6
@@ 82,8 82,8 @@ type Config struct {
Password string `toml:"password"`
DbPath string `toml:"db_path"`
- EmailConfig EmailConfig `toml:"email"`
- WebHookConfig WebhookConfig `toml:"webhook"`
+ EmailConfig *EmailConfig `toml:"email"`
+ WebhookConfig *WebhookConfig `toml:"webhook"`
}
func LoadConfig(configPath string) (*Config, error) {
@@ 112,12 112,16 @@ func (c *Config) validate() error {
}
}
- if err := c.EmailConfig.validate(); err != nil {
- return fmt.Errorf("invalid email config: %s", err)
+ if c.EmailConfig != nil {
+ if err := c.EmailConfig.validate(); err != nil {
+ return fmt.Errorf("invalid email config: %s", err)
+ }
}
- if err := c.WebHookConfig.validate(); err != nil {
- return fmt.Errorf("invalid webhook config: %s", err)
+ if c.WebhookConfig != nil {
+ if err := c.WebhookConfig.validate(); err != nil {
+ return fmt.Errorf("invalid webhook config: %s", err)
+ }
}
return nil
M main.go => main.go +6 -2
@@ 78,8 78,12 @@ func main() {
}
notifiers := make(map[string]Notifier)
- notifiers["email"] = NewEmail(conf)
- notifiers["webhook"] = NewWebhook(conf)
+ if conf.EmailConfig != nil {
+ notifiers["email"] = NewEmail(conf)
+ }
+ if conf.WebhookConfig != nil {
+ notifiers["webhook"] = NewWebhook(conf)
+ }
mfn := &Mfn{
conf: conf,
M webhook.go => webhook.go +4 -3
@@ 12,15 12,16 @@ import (
)
type Webhook struct {
- // Notifier
template *template.Template
endpoint string
}
func NewWebhook(conf *Config) *Webhook {
+ wc := conf.WebhookConfig
+
return &Webhook{
- template: conf.WebHookConfig.Template,
- endpoint: conf.WebHookConfig.Endpoint,
+ template: wc.Template,
+ endpoint: wc.Endpoint,
}
}