| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /**
- * @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"
- )
- var (
- VERSION string
- GITHASH string
- )
- // LogList 列出日志文件
- func LogList(c *gin.Context) {
- host := c.Request.Host
- if !strings.Contains(host, "http://") {
- host = "http://" + host
- }
- const templateText = `
- <h1>go查询服务信息</h1>
- <a href="{{.host}}/debug/update" title="点击后从自动构建服务拉取版本升级并重启GO服务, 请谨慎点击" target="_blank">点击升级到最新版本</a>
- <p>===========================</p>
- version : {{.version}}<br>
- git hash: {{.githash}}<br>
- oracle : {{.db}} <br>
- mysql : {{.mysql}} <br>
- redis : {{.redis}} <br>
- <br>
- <a href="{{.host}}/swagger/index.html" target="_blank">点击打开swagger</a>
- <br><br>
- <a href="{{.host}}/debug/token" title="仅当调试模式内网段才能成功设置" target="_blank">点击设置token(用于swagger查询)</a>
- <h1>日志文件列表</h1>
- <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)
- mysql := fmt.Sprintf("%s/***@%s:%v/%s",
- config.SerCfg.MySQLCfg.Username,
- config.SerCfg.MySQLCfg.Host,
- config.SerCfg.MySQLCfg.Port,
- config.SerCfg.MySQLCfg.DBName)
- redis := fmt.Sprintf("%s:%v", config.SerCfg.RedisCfg.Address, config.SerCfg.RedisCfg.Port)
- 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)
- lk2 := fmt.Sprintf(`<a href="%v/debug/log/view?filename=%v" target="_blank">查看</a>`, host, v.Name())
- lk = lk + " " + lk2
- 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),
- "mysql": template.HTML(mysql), "redis": template.HTML(redis),
- "version": template.HTML(VERSION), "githash": template.HTML(GITHASH)})
- } else {
- c.String(400, "index err.")
- }
- } else {
- c.JSON(http.StatusBadRequest, gin.H{"message": "can't list the file"})
- }
- }
|