2 files changed
+20
-1
No files matched your search
@@ -1,10 +1,14 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/bitly/go-simplejson"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk"
|
"github.com/go-admin-team/go-admin-core/sdk"
|
||||||
"github.com/go-admin-team/go-admin-core/sdk/runtime"
|
"github.com/go-admin-team/go-admin-core/sdk/runtime"
|
||||||
"github.com/go-admin-team/go-admin-core/storage"
|
"github.com/go-admin-team/go-admin-core/storage"
|
||||||
@@ -58,8 +62,22 @@ func SaveSysApi(message storage.Messager) (err error) {
|
|||||||
strings.Contains(v.RelativePath, "/static/") ||
|
strings.Contains(v.RelativePath, "/static/") ||
|
||||||
strings.Contains(v.RelativePath, "/form-generator/") ||
|
strings.Contains(v.RelativePath, "/form-generator/") ||
|
||||||
strings.Contains(v.RelativePath, "/sys/tables") {
|
strings.Contains(v.RelativePath, "/sys/tables") {
|
||||||
|
|
||||||
|
// 根据接口方法注释里的@Summary填充接口名称,适用于代码生成器
|
||||||
|
// 可在此处增加配置路径前缀的if判断,只对代码生成的自建应用进行定向的接口名称填充
|
||||||
|
busType := "BUS" // 默认"业务"类型
|
||||||
|
jsonFile, _ := ioutil.ReadFile("docs/swagger.json")
|
||||||
|
jsonData, _ := simplejson.NewFromReader(bytes.NewReader(jsonFile))
|
||||||
|
urlPath := v.RelativePath
|
||||||
|
idPatten := "(.*)/:(\\w+)" // 正则替换,把:id换成{id}
|
||||||
|
reg, _ := regexp.Compile(idPatten)
|
||||||
|
if reg.MatchString(urlPath) {
|
||||||
|
urlPath = reg.ReplaceAllString(v.RelativePath, "${1}/{${2}}") // 把:id换成{id}
|
||||||
|
}
|
||||||
|
apiTitle, _ := jsonData.Get("paths").Get(urlPath).Get(strings.ToLower(v.HttpMethod)).Get("summary").String()
|
||||||
|
|
||||||
err := d.Debug().Where(SysApi{Path: v.RelativePath, Action: v.HttpMethod}).
|
err := d.Debug().Where(SysApi{Path: v.RelativePath, Action: v.HttpMethod}).
|
||||||
Attrs(SysApi{Handle: v.Handler}).
|
Attrs(SysApi{Handle: v.Handler, Title: apiTitle, Type: busType}).
|
||||||
FirstOrCreate(&SysApi{}).
|
FirstOrCreate(&SysApi{}).
|
||||||
//Update("handle", v.Handler).
|
//Update("handle", v.Handler).
|
||||||
Error
|
Error
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ require (
|
|||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
|
||||||
github.com/alibaba/sentinel-golang v0.6.1
|
github.com/alibaba/sentinel-golang v0.6.1
|
||||||
github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5
|
github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5
|
||||||
|
github.com/bitly/go-simplejson v0.5.0
|
||||||
github.com/bytedance/go-tagexpr/v2 v2.7.12
|
github.com/bytedance/go-tagexpr/v2 v2.7.12
|
||||||
github.com/casbin/casbin/v2 v2.25.1
|
github.com/casbin/casbin/v2 v2.25.1
|
||||||
github.com/gin-gonic/gin v1.7.2
|
github.com/gin-gonic/gin v1.7.2
|
||||||
|
|||||||
Reference in new issue
Block a user