|
|
@@ -0,0 +1,57 @@
|
|
|
+/**
|
|
|
+* @Author: zou.yingbin
|
|
|
+* @Create : 2021/10/15 16:28
|
|
|
+* @Modify : 2021/10/15 16:28
|
|
|
+ */
|
|
|
+
|
|
|
+package other
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "github.com/gin-gonic/gin"
|
|
|
+ "html/template"
|
|
|
+ "io/ioutil"
|
|
|
+ "mtp2_if/config"
|
|
|
+ "net/http"
|
|
|
+ "strings"
|
|
|
+)
|
|
|
+
|
|
|
+// LogList 列出日志文件
|
|
|
+func LogList(c *gin.Context) {
|
|
|
+ host := c.Request.Host
|
|
|
+ if !strings.Contains(host, "http://") {
|
|
|
+ host = "http://" + host
|
|
|
+ }
|
|
|
+
|
|
|
+ const templateText = `
|
|
|
+<h1>日志文件列表</h1>
|
|
|
+{{.db}}
|
|
|
+<p>------------------------</p>
|
|
|
+{{.data}}
|
|
|
+<p>------------------------</p>
|
|
|
+`
|
|
|
+ sFile := make([]string, 0)
|
|
|
+ path := config.SerCfg.LogCfg.LogPath
|
|
|
+ db := fmt.Sprintf("%s/***@%s:%s/%s",
|
|
|
+ config.SerCfg.DbCfg.DbUser,
|
|
|
+ config.SerCfg.DbCfg.DbAddress,
|
|
|
+ config.SerCfg.DbCfg.DbPort,
|
|
|
+ config.SerCfg.DbCfg.DbName)
|
|
|
+ if d, err := ioutil.ReadDir(path); err == nil {
|
|
|
+ for _, v := range d {
|
|
|
+ if !v.IsDir() {
|
|
|
+ lk := fmt.Sprintf(`<a href="%v/debug/download?filename=%v" target="_blank">%v</a> size:%.2f k`,
|
|
|
+ host, v.Name(), v.Name(), float64(v.Size())/1024.0)
|
|
|
+ sFile = append(sFile, lk)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ str := strings.Join(sFile, "\n<br>")
|
|
|
+ if tmpl, err := template.New("index").Parse(templateText); err == nil {
|
|
|
+ _ = tmpl.Execute(c.Writer, gin.H{"data": template.HTML(str), "db": template.HTML(db)})
|
|
|
+ } else {
|
|
|
+ c.String(400, "index err.")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ c.JSON(http.StatusBadRequest, gin.H{"message": "can't list the file"})
|
|
|
+ }
|
|
|
+}
|