mirror of https://github.com/Xhofe/alist
chore: enable all pprof handle on debug
parent
d5b68a91d2
commit
cd2f8077fa
|
@ -1,12 +1,20 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/server/common"
|
"github.com/alist-org/alist/v3/server/common"
|
||||||
"github.com/alist-org/alist/v3/server/middlewares"
|
"github.com/alist-org/alist/v3/server/middlewares"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dev(g *gin.RouterGroup) {
|
func _pprof(g *gin.RouterGroup) {
|
||||||
|
g.Any("/*name", gin.WrapH(http.DefaultServeMux))
|
||||||
|
}
|
||||||
|
|
||||||
|
func debug(g *gin.RouterGroup) {
|
||||||
g.GET("/path/*path", middlewares.Down, func(ctx *gin.Context) {
|
g.GET("/path/*path", middlewares.Down, func(ctx *gin.Context) {
|
||||||
rawPath := ctx.MustGet("path").(string)
|
rawPath := ctx.MustGet("path").(string)
|
||||||
ctx.JSON(200, gin.H{
|
ctx.JSON(200, gin.H{
|
||||||
|
@ -16,4 +24,9 @@ func dev(g *gin.RouterGroup) {
|
||||||
g.GET("/hide_privacy", func(ctx *gin.Context) {
|
g.GET("/hide_privacy", func(ctx *gin.Context) {
|
||||||
common.ErrorStrResp(ctx, "This is ip: 1.1.1.1", 400)
|
common.ErrorStrResp(ctx, "This is ip: 1.1.1.1", 400)
|
||||||
})
|
})
|
||||||
|
g.GET("/gc", func(c *gin.Context) {
|
||||||
|
runtime.GC()
|
||||||
|
c.String(http.StatusOK, "ok")
|
||||||
|
})
|
||||||
|
_pprof(g.Group("/pprof"))
|
||||||
}
|
}
|
|
@ -71,8 +71,8 @@ func Init(e *gin.Engine) {
|
||||||
|
|
||||||
_fs(auth.Group("/fs"))
|
_fs(auth.Group("/fs"))
|
||||||
admin(auth.Group("/admin", middlewares.AuthAdmin))
|
admin(auth.Group("/admin", middlewares.AuthAdmin))
|
||||||
if flags.Dev {
|
if flags.Debug || flags.Dev {
|
||||||
dev(g.Group("/dev"))
|
debug(g.Group("/debug"))
|
||||||
}
|
}
|
||||||
static.Static(g, func(handlers ...gin.HandlerFunc) {
|
static.Static(g, func(handlers ...gin.HandlerFunc) {
|
||||||
e.NoRoute(handlers...)
|
e.NoRoute(handlers...)
|
||||||
|
|
|
@ -5,10 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/pprof"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/cmd/flags"
|
|
||||||
"github.com/alist-org/alist/v3/internal/conf"
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/setting"
|
"github.com/alist-org/alist/v3/internal/setting"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
|
@ -85,8 +83,6 @@ func Static(r *gin.RouterGroup, noRoute func(handlers ...gin.HandlerFunc)) {
|
||||||
c.Status(200)
|
c.Status(200)
|
||||||
if strings.HasPrefix(c.Request.URL.Path, "/@manage") {
|
if strings.HasPrefix(c.Request.URL.Path, "/@manage") {
|
||||||
_, _ = c.Writer.WriteString(conf.ManageHtml)
|
_, _ = c.Writer.WriteString(conf.ManageHtml)
|
||||||
} else if strings.HasPrefix(c.Request.URL.Path, "/debug/pprof") && flags.Debug {
|
|
||||||
pprof.Index(c.Writer, c.Request)
|
|
||||||
} else {
|
} else {
|
||||||
_, _ = c.Writer.WriteString(conf.IndexHtml)
|
_, _ = c.Writer.WriteString(conf.IndexHtml)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue