MCPcopy Index your code
hub / github.com/TruthHun/DocHub / HandleLogs

Method HandleLogs

controllers/AdminControllers/SysController.go:132–154  ·  view source on GitHub ↗

下载或者删除日志文件

()

Source from the content-addressed store, hash-verified

130
131//下载或者删除日志文件
132func (this *SysController) HandleLogs() {
133 file := this.GetString("file")
134 action := this.GetString("action")
135 if action == "del" { //删除
136 if ext := filepath.Ext(file); ext == ".log" {
137 if file == "logs/dochub.log" {
138 this.Response(map[string]interface{}{"status": 0, "msg": "日志文件删除失败:logs/dochub.log日志文件禁止删除,否则程序无法写入日志"})
139 }
140 if err := os.Remove(file); err != nil {
141 this.Response(map[string]interface{}{"status": 0, "msg": "日志文件删除失败:" + err.Error()})
142 }
143 }
144 this.Response(map[string]interface{}{"status": 1, "msg": "删除成功"})
145 } else { //下载
146 if b, err := ioutil.ReadFile(file); err != nil {
147 helper.Logger.Error(err.Error())
148 this.Abort("404")
149 } else {
150 this.Ctx.ResponseWriter.Header().Add("Content-disposition", "attachment; filename="+filepath.Base(file))
151 this.Ctx.ResponseWriter.Write(b)
152 }
153 }
154}
155
156//重建全量索引
157func (this *SysController) RebuildAllIndex() {

Callers

nothing calls this directly

Calls 2

ResponseMethod · 0.80
AddMethod · 0.80

Tested by

no test coverage detected