Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/liwss/rulex into dev-http…
Browse files Browse the repository at this point in the history
…_server
  • Loading branch information
liwss committed Aug 3, 2023
2 parents c0e94c5 + ff7eff8 commit 0358de5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plugin/http_server/http_api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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的哲学啊(大道至简???)
Expand All @@ -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)
Expand Down
41 changes: 41 additions & 0 deletions plugin/http_server/server/apiserver.go
Original file line number Diff line number Diff line change
@@ -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) {

}

0 comments on commit 0358de5

Please sign in to comment.