-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (47 loc) · 1.44 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
package main
import (
"github.com/julienschmidt/httprouter"
"github.com/proshik/githubstatbot/api"
"github.com/proshik/githubstatbot/config"
"github.com/proshik/githubstatbot/github"
"github.com/proshik/githubstatbot/storage"
"github.com/proshik/githubstatbot/telegram"
"log"
"net/http"
"os"
)
func main() {
cfg, err := config.Load()
if err != nil {
panic(err)
}
// config logging
log.SetOutput(os.Stdout)
// init connect postgresql
db := storage.NewPostgres(cfg.DbUrl)
// create storage for generated statuses for request to github.com
stateStore := storage.NewStateStore()
// create oAuth object
oAuth := github.NewOAuth(cfg.GitHubClientId, cfg.GitHubClientSecret)
// create Telegram Bot object
bot, err := telegram.NewBot(cfg.TelegramToken, false, db, stateStore, oAuth)
if err != nil {
log.Panic(err)
}
// run major method for read updates messages from telegram
go bot.ReadUpdates()
// initialize handler
basicAuth := &api.BasicAuth{Username: cfg.AuthBasicUsername, Password: cfg.AuthBasicPassword}
handler := api.New(oAuth, db, stateStore, bot, basicAuth, cfg.StaticFilesDir)
// configuration router
router := httprouter.New()
router.GET("/", handler.Index)
router.GET("/version", handler.Version)
router.GET("/github_redirect", handler.GitHubRedirect)
//Run HTTP server
log.Printf("Starting HTTP server on port %s\n", cfg.Port)
err = http.ListenAndServe(":"+cfg.Port, router)
if err != nil {
panic(err)
}
}