You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.7 KiB
74 lines
1.7 KiB
package main
|
|
|
|
import (
|
|
"GoClouds/core/comms"
|
|
"GoClouds/models"
|
|
"GoClouds/webs/sys/route"
|
|
"GoClouds/webs/sys/routehb"
|
|
"context"
|
|
hbtp "github.com/mgr9525/HyperByte-Transfer-Protocol"
|
|
"github.com/mgr9525/go-cloud"
|
|
"github.com/sirupsen/logrus"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
if err := gocloud.Init(); err != nil {
|
|
println("ReadYamlConf err:" + err.Error())
|
|
return
|
|
}
|
|
/*if err := gocloud.ReadYamlConf("custom.yml", app.Conf); err != nil {
|
|
println("ReadYamlConf err:" + err.Error())
|
|
return
|
|
}*/
|
|
err := initFuns()
|
|
if err != nil {
|
|
println("initFuns err:" + err.Error())
|
|
os.Exit(1)
|
|
}
|
|
go StartConnEngine(gocloud.CloudConf.Custom.GetString("hbtpHost"))
|
|
if err := gocloud.Run(); err != nil {
|
|
logrus.Errorf("gocloud run err:%v", err)
|
|
}
|
|
}
|
|
|
|
func initFuns() error {
|
|
err := comms.InitDb()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = SyncTable()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
gocloud.Web.Use(gocloud.MidAccessAllowFun)
|
|
gocloud.RegController(&route.IndexHandler{})
|
|
/*gocloud.Web.FuncMap["MgrsHost"] = func() string {
|
|
return comm.MgrsHost
|
|
}*/
|
|
return nil
|
|
}
|
|
func SyncTable() error {
|
|
if comms.DbSysHelper.GetDB() == nil {
|
|
return nil
|
|
}
|
|
isext, err := comms.DbSysHelper.GetDB().IsTableExist(models.SysUser{})
|
|
if err == nil && !isext {
|
|
comms.DbSysHelper.GetDB().ImportFile("my.sql")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func StartConnEngine(host string) {
|
|
if host == "" {
|
|
logrus.Error("StartConnEngine run err:host is empty")
|
|
os.Exit(1)
|
|
}
|
|
eng := hbtp.NewEngine(context.Background())
|
|
eng.RegFun(1, hbtp.RPCFunHandle(&routehb.CommRPC{}))
|
|
eng.RegFun(2, hbtp.RPCFunHandle(&routehb.UserRPC{}))
|
|
if err := eng.Run(host); err != nil {
|
|
logrus.Error("StartConnEngine run err:" + err.Error())
|
|
os.Exit(1)
|
|
}
|
|
}
|