-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (41 loc) · 1.21 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
54
55
package main
import (
"os"
"strconv"
"github.com/Logiraptor/go-pivotaltracker/v5/pivotal"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/slack-go/slack"
"github.com/flexoid/pivotal-slack-preview/internal/webservice"
)
const defaultPort = "8080"
const defaultStoriesCountToAsk = 2
var version = "vX.Y.Z"
func main() {
logger := setupLogger()
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
log.Debug().Msgf("defaulting to port %s", port)
}
pivotalClient := pivotal.NewClient(os.Getenv("PIVOTAL_TOKEN"))
slackClient := slack.New(os.Getenv("SLACK_TOKEN"))
signingSecret := os.Getenv("SLACK_SIGNING_SECRET")
storiesCountToAsk := defaultStoriesCountToAsk
if count, err := strconv.Atoi(os.Getenv("STORIES_COUNT_TO_ASK")); err == nil {
storiesCountToAsk = count
}
server := webservice.Server{
Port: port,
SlackClient: slackClient,
SlackSigningSecret: signingSecret,
PivotalClient: pivotalClient,
Logger: &logger,
StoriesCountToAsk: storiesCountToAsk,
}
logger.Info().Msgf("Starting slack-pivotalbot %s", version)
server.Start()
}
func setupLogger() zerolog.Logger {
return zerolog.New(os.Stdout).With().Timestamp().Logger()
}