Skip to content

Commit 5db8d6f

Browse files
author
bajins
committed
添加格式化nginx配置功能
1 parent ca66e5f commit 5db8d6f

File tree

13 files changed

+2625
-48
lines changed

13 files changed

+2625
-48
lines changed

controller.go

Lines changed: 54 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ import (
1414
"runtime"
1515
)
1616

17-
/**
18-
* 首页
19-
*
20-
* @Description
21-
* @author claer www.bajins.com
22-
* @date 2019/6/28 11:19
23-
*/
17+
// 首页
2418
func WebRoot(c *gin.Context) {
2519
// 301重定向
2620
//c.Redirect(http.StatusMovedPermanently, "/static")
@@ -29,14 +23,7 @@ func WebRoot(c *gin.Context) {
2923
c.HTML(http.StatusOK, "index.html", gin.H{})
3024
}
3125

32-
/**
33-
* 获取系统信息
34-
*
35-
* @return
36-
* @Description
37-
* @author claer www.bajins.com
38-
* @date 2019/7/16 14:49
39-
*/
26+
// 获取系统信息
4027
func SystemInfo(c *gin.Context) {
4128
data := make(map[string]interface{}, 0)
4229
data["Version"] = utils.ToUpper(runtime.Version())
@@ -58,12 +45,7 @@ func SystemInfo(c *gin.Context) {
5845
c.JSON(http.StatusOK, result.Success("获取系统信息成功", data))
5946
}
6047

61-
/**
62-
* 获取key
63-
*
64-
* @author claer www.bajins.com
65-
* @date 2019/6/28 15:04
66-
*/
48+
// 获取key
6749
func GetKey(c *gin.Context) {
6850
// GET 获取参数内容,没有则返回空字符串
6951
//company := c.Query("company")
@@ -88,25 +70,24 @@ func GetKey(c *gin.Context) {
8870
dir, err := os.Getwd()
8971
if err != nil {
9072
log.Error(err)
91-
c.JSON(http.StatusOK, result.Error(500, "获取key系统错误"))
73+
c.JSON(http.StatusOK, result.SystemError())
9274
return
9375
}
94-
way := path.Join(dir, "pyutils")
9576
if company == "netsarang" {
96-
out, err := utils.ExecutePython(path.Join(way, "xshell_key.py"), app, version)
77+
out, err := utils.ExecutePython(path.Join(dir, "pyutils", "xshell_key.py"), app, version)
9778
if err != nil {
9879
log.Error(err)
9980
fmt.Println(err)
100-
c.JSON(http.StatusOK, result.Error(500, "获取key系统错误"))
81+
c.JSON(http.StatusOK, result.SystemError())
10182
return
10283
}
10384
c.JSON(http.StatusOK, result.Success("获取key成功", map[string]string{"key": out}))
10485

10586
} else if company == "mobatek" {
10687

107-
_, err := utils.ExecutePython(path.Join(way, "moba_xterm_Keygen.py"), utils.OsPath(), version)
88+
_, err := utils.ExecutePython(path.Join(dir, "pyutils", "moba_xterm_Keygen.py"), utils.OsPath(), version)
10889
if err != nil {
109-
c.JSON(http.StatusOK, result.Error(500, "获取key系统错误"))
90+
c.JSON(http.StatusOK, result.SystemError())
11091
return
11192
}
11293
c.Header("Content-Type", "application/octet-stream")
@@ -116,22 +97,17 @@ func GetKey(c *gin.Context) {
11697
c.FileAttachment(utils.OsPath()+"/Custom.mxtpro", "Custom.mxtpro")
11798

11899
} else if company == "torchsoft" {
119-
out, err := utils.ExecutePython(path.Join(way, "reg_workshop_keygen.py"), version)
100+
out, err := utils.ExecutePython(path.Join(dir, "pyutils", "reg_workshop_keygen.py"), version)
120101
if err != nil {
121-
c.JSON(http.StatusOK, result.Error(500, "获取key系统错误"))
102+
c.JSON(http.StatusOK, result.SystemError())
122103
return
123104
}
124105
c.JSON(http.StatusOK, result.Success("获取key成功", map[string]string{"key": out}))
125106
}
126107

127108
}
128109

129-
/**
130-
* 文件上传请求
131-
*
132-
* @author claer www.bajins.com
133-
* @date 2019/6/28 11:32
134-
*/
110+
// 文件上传请求
135111
func Upload(c *gin.Context) {
136112
// 拿到上传的文件的信息
137113
file, header, err := c.Request.FormFile("upload")
@@ -149,12 +125,7 @@ func Upload(c *gin.Context) {
149125
}
150126
}
151127

152-
/**
153-
* 文件下载请求
154-
*
155-
* @author claer www.bajins.com
156-
* @date 2019/6/28 11:33
157-
*/
128+
// 文件下载请求
158129
func Dowload(c *gin.Context) {
159130
response, err := http.Get(c.Request.Host + "/static/public/favicon.ico")
160131
if err != nil || response.StatusCode != http.StatusOK {
@@ -169,8 +140,8 @@ func Dowload(c *gin.Context) {
169140
c.DataFromReader(http.StatusOK, response.ContentLength, response.Header.Get("Content-Type"), response.Body, extraHeaders)
170141
}
171142

172-
// Netsarang
173-
func Netsarang(c *gin.Context) {
143+
// Netsarang下载页面
144+
func NetsarangDownloadIndex(c *gin.Context) {
174145
// 301重定向
175146
//c.Redirect(http.StatusMovedPermanently, "/static")
176147
// 返回HTML页面
@@ -194,8 +165,47 @@ func GetXshellUrl(c *gin.Context) {
194165
url, err := reptile.DownloadNetsarang(app)
195166
if err != nil {
196167
log.Error(err)
197-
c.JSON(http.StatusOK, result.Error(500, "系统错误"))
168+
c.JSON(http.StatusOK, result.SystemError())
198169
return
199170
}
200171
c.JSON(http.StatusOK, result.Success("获取"+app+"成功", map[string]string{"url": url}))
201172
}
173+
174+
// NGINX格式化代码页面
175+
func NginxFormatIndex(c *gin.Context) {
176+
// 301重定向
177+
//c.Redirect(http.StatusMovedPermanently, "/static")
178+
// 返回HTML页面
179+
//c.HTML(http.StatusOK, "index.html", nil)
180+
c.HTML(http.StatusOK, "nginx-format.html", gin.H{})
181+
}
182+
183+
// 格式化nginx配置代码
184+
func NginxFormatPython(c *gin.Context) {
185+
// GET 获取参数内容,没有则返回空字符串
186+
//code := c.Query("code")
187+
// POST 获取的所有参数内容的类型都是 string
188+
code := c.PostForm("code")
189+
190+
if utils.IsStringEmpty(code) {
191+
c.JSON(http.StatusOK, result.Error(300, "请输入配置代码"))
192+
return
193+
}
194+
// 获取当前绝对路径
195+
dir, err := os.Getwd()
196+
if err != nil {
197+
log.Error(err)
198+
c.JSON(http.StatusOK, result.SystemError())
199+
return
200+
}
201+
out, err := utils.ExecutePython(path.Join(dir, "pyutils", "nginxfmt.py"), code)
202+
if err != nil {
203+
log.Error(err)
204+
c.JSON(http.StatusOK, result.SystemError())
205+
return
206+
}
207+
res := make(map[string]string)
208+
res["contents"] = out
209+
c.JSON(http.StatusOK, result.Success("请求成功", res))
210+
211+
}

key-gin.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ func main() {
9595
router.POST("/getKey", GetKey)
9696
router.POST("/SystemInfo", SystemInfo)
9797
router.Any("/", WebRoot)
98-
router.Any("/download", Netsarang)
98+
router.Any("/download", NetsarangDownloadIndex)
9999
router.POST("/getXshellUrl", GetXshellUrl)
100+
router.Any("/nginx-format", NginxFormatIndex)
101+
router.POST("/nginx-format-py", NginxFormatPython)
100102

101103
// 注册一个目录,gin 会把该目录当成一个静态的资源目录
102104
// 该目录下的资源看可以按照路径访问

0 commit comments

Comments
 (0)