This repository has been archived by the owner on Oct 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (40 loc) · 1.47 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
package main
import (
log "github.com/sirupsen/logrus"
"github.com/ubclaunchpad/rocket/bot"
"github.com/ubclaunchpad/rocket/config"
"github.com/ubclaunchpad/rocket/github"
"github.com/ubclaunchpad/rocket/plugin"
"github.com/ubclaunchpad/rocket/server"
"github.com/ubclaunchpad/rocket/data"
)
func main() {
// Create a configuration object by pulling the value of a bunch of
// environment variables.
cfg := config.FromEnv()
// Connect the database and initialize the data access layer. We use the
// URL, database, and password specified in the config. This will panic
// if we fail to connect to the database.
dal := data.New(cfg)
defer func() {
if err := dal.Close(); err != nil {
log.WithError(err)
}
}()
// Create a client to the GitHub API, using the token from the config.
gh := github.New("ubclaunchpad", cfg)
// Set up a server listening on the interface specified in the
// config. This will panic if the server fails to bind to the interface
// or dies for any reason after beginning listening.
srv := server.New(cfg, dal, gh, log.WithField("service", "server"))
// Set up the Slack bot. This will create an RTM that receives
// events from Slack and respond to them as needed.
slackBot := bot.New(cfg, dal, gh, log.WithField("service", "slack"))
// Load plugins
if err := plugin.RegisterPlugins(slackBot); err != nil {
slackBot.Log.WithError(err).Fatal("Failed to load plugins")
}
// Start Slack bot and HTTP server
go srv.Start()
slackBot.Start()
}