-
Notifications
You must be signed in to change notification settings - Fork 14
/
slack_api.go
27 lines (24 loc) · 922 Bytes
/
slack_api.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
package registry
import (
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/config"
slackapi "github.com/coretrix/hitrix/service/component/slack_api"
"github.com/juju/errors"
"github.com/sarulabs/di"
)
func ServiceDefinitionSlackAPI() *service.Definition {
return &service.Definition{
Name: service.SlackAPIService,
Global: true,
Build: func(ctn di.Container) (interface{}, error) {
slackConfig := ctn.Get(service.ConfigService).(*config.Config).GetStringMap("slack")
if slackConfig["token"] == "" {
return nil, errors.New("missing slack.token")
}
if slackConfig["error_channel"] != "" && slackConfig["dev_panel_url"] != "" {
return slackapi.NewSlack(slackConfig["token"].(string), slackConfig["error_channel"].(string), slackConfig["dev_panel_url"].(string)), nil
}
return slackapi.NewSlack(slackConfig["token"].(string), "", ""), nil
},
}
}