-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
70 lines (60 loc) · 1.35 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"github.com/SGE-AI/sge-bot/config"
"github.com/SGE-AI/sge-bot/interfaces"
"github.com/SGE-AI/sge-bot/logger"
"github.com/SGE-AI/sge-bot/slackapi"
"github.com/joho/godotenv"
"net/http"
"os"
)
type Application struct {
config config.Config
logger logger.Logger
socket interfaces.SocketConnection
slack slackapi.SlackAPI
}
func ProvideApplication(
config config.Config,
logger logger.Logger,
socket interfaces.SocketConnection,
slack slackapi.SlackAPI,
) *Application {
return &Application{
config: config,
logger: logger,
socket: socket,
slack: slack,
}
}
func handleRequests(port string) {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("OK"))
})
err := http.ListenAndServe(port, nil)
if err != nil {
panic(err)
}
}
func main() {
_ = godotenv.Load()
var app *Application
app = initializeApp()
botUser, err := app.slack.GetBotUserId()
if err != nil {
app.logger.Log(logger.ERROR, err.Error())
os.Exit(1)
}
app.config.SetBotUserID(botUser)
app.logger.Log(logger.INFO, "bot user id: %s", app.config.BotUserID())
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
app.logger.Log(logger.INFO, "http listening on port %s", port)
go handleRequests(":" + port)
err = app.socket.Run()
if err != nil {
app.logger.Log(logger.ERROR, err.Error())
}
}