From b92326bcd8b455c9a68cc0d85e5862987053ab91 Mon Sep 17 00:00:00 2001 From: jinnrry Date: Thu, 2 Jun 2022 15:19:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwindows=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.go | 2 ++ services/admin.go | 6 +++--- services/apiResponse.go | 2 +- views/edit.html | 24 +++++++++++++++++++++++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index 71c282c..20cb0fd 100644 --- a/config/config.go +++ b/config/config.go @@ -7,6 +7,8 @@ import ( "strings" ) +const Separator = "```" + type Config struct { ApiServerPort int AdminServerPort int diff --git a/services/admin.go b/services/admin.go index 4e7d289..938004a 100644 --- a/services/admin.go +++ b/services/admin.go @@ -17,7 +17,7 @@ func UpsertApi(apiPath string, info *ApiInfo) error { apiPath = "/" + apiPath } - dataPath := strings.Replace(apiPath, "/", "|||", -1) + dataPath := strings.Replace(apiPath, "/", config.Separator, -1) _ = os.MkdirAll(config.RunConfig.DataPath+dataPath, 0777) @@ -48,7 +48,7 @@ func GetApiList() ([]apiItem, error) { return nil, err } for _, file := range dirList { - apiPath := strings.Replace(file.Name(), "|||", "/", -1) + apiPath := strings.Replace(file.Name(), config.Separator, "/", -1) if config.RunConfig.ApiServerPort != 80 { api = append(api, apiItem{ @@ -67,7 +67,7 @@ func GetApiList() ([]apiItem, error) { } func DeleteApi(path string) error { - dataPath := strings.Replace(path, "/", "|||", -1) + dataPath := strings.Replace(path, "/", config.Separator, -1) dirPath := config.RunConfig.DataPath + dataPath return os.RemoveAll(dirPath) } diff --git a/services/apiResponse.go b/services/apiResponse.go index c81f6e7..96bb3bb 100644 --- a/services/apiResponse.go +++ b/services/apiResponse.go @@ -28,7 +28,7 @@ type ApiInfo struct { func GetApiInfo(apiPath string) (*ApiInfo, error) { ret := &ApiInfo{} // 加载设置文件 - dataPath := strings.Replace(apiPath, "/", "|||", -1) + dataPath := strings.Replace(apiPath, "/", config.Separator, -1) filePtr, err := os.Open(config.RunConfig.DataPath + dataPath + "/settings.json") if err != nil { return nil, errors.New("接口不存在") diff --git a/views/edit.html b/views/edit.html index 911462c..e0d541f 100644 --- a/views/edit.html +++ b/views/edit.html @@ -107,10 +107,32 @@ } else { alert(data.msg) } - },"json"); + }, "json"); + }, + getUrlKey: function (name) { + return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null } }, created: function () { + let that = this; + let path = this.getUrlKey("path"); + + this.apiPath = path; + + if (path != "") { + $.get("/apiDetail", {api: path}, function (ret) { + if (ret.success === 0) { + that.httpCode = ret.data.http_code; + that.wait = ret.data.wait; + that.methods = ret.data.method; + that.response = ret.data.response; + that.responseHead = ret.data.header; + that.script = ret.data.custom_function; + } + }, "json") + } + + } })