Skip to content

Commit

Permalink
修改trojan日志等级接口
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Apr 12, 2020
1 parent 0258b48 commit c47f8c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
28 changes: 13 additions & 15 deletions web/controller/trojan.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@ func Restart() *ResponseBody {
return &responseBody
}

// Status trojan状态
func Status() *ResponseBody {
responseBody := ResponseBody{Msg: "success"}
defer TimeCost(time.Now(), &responseBody)
config := core.Load("")
responseBody.Data = map[string]interface{}{
"status": trojan.Status(false),
"version": trojan.Version(),
"loglevel": config.LogLevel,
}
return &responseBody
}

// Update trojan更新
func Update() *ResponseBody {
responseBody := ResponseBody{Msg: "success"}
Expand All @@ -56,15 +43,26 @@ func Update() *ResponseBody {
return &responseBody
}

// LogLevel 修改trojan日志等级
func LogLevel(level int) *ResponseBody {
// SetLogLevel 修改trojan日志等级
func SetLogLevel(level int) *ResponseBody {
responseBody := ResponseBody{Msg: "success"}
defer TimeCost(time.Now(), &responseBody)
core.WriteLogLevel(level)
trojan.Restart()
return &responseBody
}

// GetLogLevel 获取trojan日志等级
func GetLogLevel() *ResponseBody {
responseBody := ResponseBody{Msg: "success"}
defer TimeCost(time.Now(), &responseBody)
config := core.Load("")
responseBody.Data = map[string]interface{}{
"loglevel": config.LogLevel,
}
return &responseBody
}

// Log 通过ws查看trojan实时日志
func Log(c *gin.Context) {
var (
Expand Down
6 changes: 3 additions & 3 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ func trojanRouter(router *gin.Engine) {
router.POST("/trojan/restart", func(c *gin.Context) {
c.JSON(200, controller.Restart())
})
router.GET("/trojan/status", func(c *gin.Context) {
c.JSON(200, controller.Status())
router.GET("/trojan/loglevel", func(c *gin.Context) {
c.JSON(200, controller.GetLogLevel())
})
router.POST("/trojan/update", func(c *gin.Context) {
c.JSON(200, controller.Update())
})
router.POST("/trojan/loglevel", func(c *gin.Context) {
slevel := c.DefaultPostForm("level", "1")
level, _ := strconv.Atoi(slevel)
c.JSON(200, controller.LogLevel(level))
c.JSON(200, controller.SetLogLevel(level))
})
router.GET("/trojan/log", func(c *gin.Context) {
controller.Log(c)
Expand Down

0 comments on commit c47f8c0

Please sign in to comment.