mtfosbot/main.go

58 lines
1.2 KiB
Go
Raw Normal View History

2018-08-14 09:25:34 +00:00
package main
import (
2018-09-17 16:35:48 +00:00
"encoding/gob"
2018-08-14 09:25:34 +00:00
"log"
"strconv"
"strings"
"git.trj.tw/golang/mtfosbot/model"
2018-09-10 10:13:27 +00:00
"git.trj.tw/golang/mtfosbot/module/background"
2018-08-22 09:20:12 +00:00
"git.trj.tw/golang/mtfosbot/module/config"
2018-09-13 10:18:59 +00:00
twitchirc "git.trj.tw/golang/mtfosbot/module/twitch-irc"
2018-08-14 09:25:34 +00:00
"git.trj.tw/golang/mtfosbot/router/routes"
"github.com/gin-gonic/gin"
)
var server *gin.Engine
func main() {
2018-08-22 09:20:12 +00:00
err := config.LoadConfig()
if err != nil {
log.Fatal(err)
2018-08-14 09:25:34 +00:00
}
2018-09-17 16:35:48 +00:00
registerTypes()
2018-09-10 10:13:27 +00:00
background.SetBackground()
2018-08-14 09:25:34 +00:00
// create http server
server = routes.NewServ()
routes.SetRoutes(server)
// connect to database
2018-08-28 03:55:38 +00:00
db, err := model.NewDB()
2018-08-14 09:25:34 +00:00
if err != nil {
log.Fatal(err)
}
2018-08-28 03:55:38 +00:00
defer db.Close()
2018-08-14 09:25:34 +00:00
2018-09-15 15:48:40 +00:00
go twitchirc.InitIRC()
2018-09-13 10:18:59 +00:00
2018-08-22 09:20:12 +00:00
server.Run(strings.Join([]string{":", strconv.Itoa(config.GetConf().Port)}, ""))
2018-08-14 09:25:34 +00:00
}
2018-09-17 16:35:48 +00:00
func registerTypes() {
gob.Register(model.Account{})
gob.Register(model.Commands{})
gob.Register(model.DonateSetting{})
gob.Register(model.FacebookPage{})
gob.Register(model.KeyCommands{})
gob.Register(model.LineGroup{})
gob.Register(model.LineMessageLog{})
gob.Register(model.LineUser{})
gob.Register(model.OpayDonateList{})
gob.Register(model.TwitchChannel{})
gob.Register(model.YoutubeChannel{})
gob.Register(map[string]interface{}{})
}