mtgbot/main.go
2019-01-18 16:39:02 +08:00

53 lines
911 B
Go

package main
import (
"encoding/gob"
"fmt"
"log"
"git.trj.tw/golang/mtgbot/models"
"git.trj.tw/golang/mtgbot/modules/background"
"git.trj.tw/golang/mtgbot/modules/cmd"
"git.trj.tw/golang/mtgbot/modules/config"
"git.trj.tw/golang/mtgbot/modules/options"
"git.trj.tw/golang/mtgbot/router/routes"
)
func init() {
options.RegFlag()
}
func main() {
opts := options.GetOpts()
// Load config file
err := config.LoadConfig(opts.Config)
if err != nil {
log.Fatal(err)
}
conf := config.GetConf()
if opts.DBTool {
cmd.DBTool()
}
// init database connection
db := models.NewDB()
defer db.Close()
// register session object types
regTypes()
background.SetCronJob()
engine := routes.NewEngine()
routes.SetRoutes(engine)
engine.Run(fmt.Sprintf(":%d", conf.Port))
}
func regTypes() {
gob.Register(map[string]interface{}{})
gob.Register(models.Cards{})
gob.Register(models.Sets{})
}