package main import ( "GoClouds/core/comm" "GoClouds/models" "GoClouds/webs/sys/route" "GoClouds/webs/sys/routehb" "context" "errors" "fmt" 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) } if err := gocloud.Run(); err != nil { logrus.Errorf("gocloud run err:%v", err) } } func initFuns() error { err := comm.InitDb() if err != nil { return err } err = SyncTable() if err != nil { return err } hbhost := fmt.Sprintf("%v", gocloud.CloudConf.Custom["hbtpHost"]) if gocloud.CloudConf.Custom["hbtpHost"] == nil || hbhost == "" { return errors.New("hbtp bind host err") } go StartConnEngine(hbhost) gocloud.Web.Use(gocloud.MidAccessAllowFun) gocloud.RegController(&route.IndexHandler{}) /*gocloud.Web.FuncMap["MgrsHost"] = func() string { return comm.MgrsHost }*/ return nil } func SyncTable() error { if comm.DbSysHelper.GetDB() == nil { return nil } isext, err := comm.DbSysHelper.GetDB().IsTableExist(models.SysUser{}) if err == nil && !isext { comm.DbSysHelper.GetDB().ImportFile("my.sql") } return nil } func StartConnEngine(host string) { 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) } }