From f78d9e26cb27f0a311de618618454880f3eb0d79 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 28 Sep 2021 10:52:01 +0800 Subject: [PATCH] + API --- global/service.go | 8 +++ table/api.go | 2 +- xiang/apis/sys.http.json | 30 ---------- xiang/apis/table.http.json | 109 +++++++++++++++++++++++++++++++++++++ xiang/apis/xiang.http.json | 20 +++++++ 5 files changed, 138 insertions(+), 31 deletions(-) delete mode 100644 xiang/apis/sys.http.json create mode 100644 xiang/apis/table.http.json create mode 100644 xiang/apis/xiang.http.json diff --git a/global/service.go b/global/service.go index 2c9b6ef9..a795e5d7 100644 --- a/global/service.go +++ b/global/service.go @@ -105,6 +105,14 @@ func watchEngine(from string) { script := getFile(root, file) gou.LoadAPI(string(script.Content), "xiang."+script.Name) // Reload log.Printf("API %s 已重新加载完毕", "xiang."+script.Name) + + // 打印最新API信息 + api := gou.APIs["xiang."+script.Name] + log.Printf("%s(%d)", api.Name, len(api.HTTP.Paths)) + for _, p := range api.HTTP.Paths { + log.Println(p.Method, filepath.Join("/api", api.HTTP.Group, p.Path), "\tprocess:", p.Process) + } + } else if op == "remove" || op == "rename" { name := "xiang." + getFileName(root, file) if _, has := gou.APIs[name]; has { diff --git a/table/api.go b/table/api.go index a83b0807..eabd0256 100644 --- a/table/api.go +++ b/table/api.go @@ -120,7 +120,7 @@ func apiDefaultWhere(model *gou.Model, withs map[string]gou.With, name string, p } } -// apiDefaultSetting 接口默认值 +// apiDefaultSetting 数据表格配置默认值 func apiDefaultSetting(table *Table) API { return API{ Name: "setting", diff --git a/xiang/apis/sys.http.json b/xiang/apis/sys.http.json deleted file mode 100644 index c376fbae..00000000 --- a/xiang/apis/sys.http.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "系统接口", - "version": "1.0.0", - "description": "系统接口API", - "group": "sys", - "guard": "bearer-jwt", - "paths": [ - { - "path": "/info", - "method": "GET", - "guard": "-", - "process": "models.user.Find", - "in": ["$param.id", ":params"], - "out": { - "status": 200, - "type": "application/json" - } - }, - { - "path": "/find/:id", - "method": "GET", - "process": "models.user.Find", - "in": ["$param.id", ":params"], - "out": { - "status": 200, - "type": "application/json" - } - } - ] -} diff --git a/xiang/apis/table.http.json b/xiang/apis/table.http.json new file mode 100644 index 00000000..d1e379af --- /dev/null +++ b/xiang/apis/table.http.json @@ -0,0 +1,109 @@ +{ + "name": "数据表格接口", + "version": "1.0.0", + "description": "数据表格接口API", + "group": "xiang/table", + "guard": "bearer-jwt", + "paths": [ + { + "path": "/:name/search", + "method": "GET", + "process": "xiang.table.Search", + "in": ["$param.name", ":query-param", "$query.page", "$query.pagesize"], + "out": { + "status": 200, + "type": "application/json" + } + }, + { + "path": "/:name/find/:id", + "method": "GET", + "process": "xiang.table.Find", + "in": ["$param.name", "$param.id"], + "out": { + "status": 200, + "type": "application/json" + } + }, + { + "path": "/:name/save/:id", + "method": "POST", + "process": "xiang.table.Save", + "in": ["$param.name", ":payload"], + "out": { + "status": 200, + "type": "application/json" + } + }, + { + "path": "/:name/delete/:id", + "method": "POST", + "process": "xiang.table.Delete", + "in": ["$param.name", "$param.id"], + "out": { + "status": 200, + "type": "application/json" + } + }, + { + "path": "/:name/insert", + "method": "POST", + "process": "xiang.table.Insert", + "in": ["$param.name", ":payload"], + "out": { + "status": 200, + "type": "application/json" + } + }, + { + "path": "/:name/delete/where", + "method": "POST", + "process": "xiang.table.DeleteWhere", + "in": ["$param.name", ":query-param", ":payload"], + "out": { + "status": 200, + "type": "application/json" + } + }, + { + "path": "/:name/delete/in", + "method": "POST", + "process": "xiang.table.DeleteIn", + "in": ["$param.name", "$query.ids", ":payload"], + "out": { + "status": 200, + "type": "application/json" + } + }, + { + "path": "/:name/update/where", + "method": "POST", + "process": "xiang.table.UpdateWhere", + "in": ["$param.name", ":query-param", ":payload"], + "out": { + "status": 200, + "type": "application/json" + } + }, + { + "path": "/:name/update/in", + "method": "POST", + "process": "xiang.table.UpdateIn", + "in": ["$param.name", "$query.ids", ":payload"], + "out": { + "status": 200, + "type": "application/json" + } + }, + { + "path": "/:name/setting", + "method": "GET", + "process": "xiang.table.Setting", + "in": ["$param.name"], + "out": { + "status": 200, + "type": "application/json" + } + } + ] +} diff --git a/xiang/apis/xiang.http.json b/xiang/apis/xiang.http.json new file mode 100644 index 00000000..1ff5125f --- /dev/null +++ b/xiang/apis/xiang.http.json @@ -0,0 +1,20 @@ +{ + "name": "系统接口", + "version": "1.0.0", + "description": "系统接口API", + "group": "xiang", + "guard": "bearer-jwt", + "paths": [ + { + "path": "/ping", + "method": "GET", + "guard": "-", + "process": "xiang.ping", + "in": [], + "out": { + "status": 200, + "type": "application/json" + } + } + ] +}