diff --git a/plugin/http_server/http_api_server.go b/plugin/http_server/http_api_server.go index 29b1ec42f..07d8d46d2 100644 --- a/plugin/http_server/http_api_server.go +++ b/plugin/http_server/http_api_server.go @@ -72,9 +72,8 @@ func (s *HttpApiServer) InitDb(dbPath string) { } if err != nil { - glogger.GLogger.Error(err) // Sqlite 创建失败应该是致命错误了, 多半是环境出问题,直接给panic了, 不尝试救活 - panic(err) + glogger.GLogger.Fatal(err) } // 注册数据库配置表 // 这么写看起来是很难受, 但是这玩意就是go的哲学啊(大道至简???) @@ -88,6 +87,7 @@ func (s *HttpApiServer) InitDb(dbPath string) { &model.MApp{}, &model.MAiBase{}, &model.MModbusPointPosition{}, + &model.MVisual{}, ); err != nil { glogger.GLogger.Fatal(err) os.Exit(1) diff --git a/plugin/http_server/server/apiserver.go b/plugin/http_server/server/apiserver.go index 9ade056c4..0baf9e6ae 100644 --- a/plugin/http_server/server/apiserver.go +++ b/plugin/http_server/server/apiserver.go @@ -1,4 +1,45 @@ package server +import ( + "github.com/gin-gonic/gin" + "github.com/hootrhino/rulex/typex" +) + +/* +* +* API Server +* + */ type RulexApiServer struct { + ginEngine *gin.Engine + ruleEngine typex.RuleX +} + +/* +* +* 新建路由 +* + */ +func (ras *RulexApiServer) AddRoute(method, path string, handler func(ctx *gin.Context)) { + if method == "GET" { + ras.ginEngine.GET(path, handler) + } + if method == "POST" { + ras.ginEngine.POST(path, handler) + } + if method == "PUT" { + ras.ginEngine.PUT(path, handler) + } + if method == "DELETE" { + ras.ginEngine.DELETE(path, handler) + } +} + +/* +* +* API 调用 +* + */ +func (ras *RulexApiServer) InvokeAPI(name string) { + }