2018-12-24 06:34:13 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/gob"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
2018-12-24 09:34:24 +00:00
|
|
|
"git.trj.tw/golang/mtgbot/models"
|
2019-01-18 08:39:02 +00:00
|
|
|
"git.trj.tw/golang/mtgbot/modules/background"
|
2018-12-24 09:34:24 +00:00
|
|
|
"git.trj.tw/golang/mtgbot/modules/cmd"
|
2018-12-24 06:34:13 +00:00
|
|
|
"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()
|
|
|
|
|
2018-12-24 09:34:24 +00:00
|
|
|
if opts.DBTool {
|
|
|
|
cmd.DBTool()
|
|
|
|
}
|
|
|
|
|
|
|
|
// init database connection
|
|
|
|
db := models.NewDB()
|
|
|
|
defer db.Close()
|
|
|
|
|
2018-12-24 06:34:13 +00:00
|
|
|
// register session object types
|
|
|
|
regTypes()
|
|
|
|
|
2019-01-18 08:39:02 +00:00
|
|
|
background.SetCronJob()
|
|
|
|
|
2018-12-24 06:34:13 +00:00
|
|
|
engine := routes.NewEngine()
|
|
|
|
routes.SetRoutes(engine)
|
|
|
|
engine.Run(fmt.Sprintf(":%d", conf.Port))
|
|
|
|
}
|
|
|
|
|
|
|
|
func regTypes() {
|
|
|
|
gob.Register(map[string]interface{}{})
|
2018-12-24 09:34:24 +00:00
|
|
|
gob.Register(models.Cards{})
|
|
|
|
gob.Register(models.Sets{})
|
2018-12-24 06:34:13 +00:00
|
|
|
}
|