-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 1.26 KB
/
main.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
package main
import (
"context"
"log"
"os"
"github.com/nakamasato/cloud-run-slack-bot/pkg/cloudrun"
"github.com/nakamasato/cloud-run-slack-bot/pkg/cloudrunslackbot"
"github.com/nakamasato/cloud-run-slack-bot/pkg/monitoring"
slackinternal "github.com/nakamasato/cloud-run-slack-bot/pkg/slack"
"github.com/slack-go/slack"
)
func main() {
var err error
project := os.Getenv("PROJECT")
if project == "" {
log.Fatal("PROJECT env var is required")
}
region := os.Getenv("REGION")
if region == "" {
log.Fatal("REGION env var is required")
}
mClient, err := monitoring.NewMonitoringClient(project)
if err != nil {
log.Fatal(err)
}
defer mClient.Close()
ctx := context.Background()
rClient, err := cloudrun.NewClient(ctx, project, region)
if err != nil {
log.Fatalf("Failed to create run service: %v", err)
}
ops := []slack.Option{}
if appToken := os.Getenv("SLACK_APP_TOKEN"); appToken != "" {
ops = append(ops, slack.OptionAppLevelToken(appToken))
}
sClient := slack.New(os.Getenv("SLACK_BOT_TOKEN"), ops...)
handler := slackinternal.NewSlackEventHandler(sClient, rClient, mClient, os.Getenv("TMP_DIR"))
svc := cloudrunslackbot.NewCloudRunSlackBotService(
sClient,
os.Getenv("SLACK_CHANNEL"),
os.Getenv("SLACK_APP_MODE"),
handler,
)
svc.Run()
}