chore: standardize context keys with custom ContextKey type (#697)

* chore: standardize context keys with custom ContextKey type

* fix bug

* 使用Request.Context
This commit is contained in:
j2rong4cn
2025-07-14 23:55:17 +08:00
committed by GitHub
parent 2a4c546a8b
commit 0c461991f9
51 changed files with 253 additions and 219 deletions

View File

@ -5,6 +5,7 @@ import (
_ "net/http/pprof"
"runtime"
"github.com/OpenListTeam/OpenList/v4/internal/conf"
"github.com/OpenListTeam/OpenList/v4/internal/sign"
"github.com/OpenListTeam/OpenList/v4/server/common"
"github.com/OpenListTeam/OpenList/v4/server/middlewares"
@ -16,14 +17,14 @@ func _pprof(g *gin.RouterGroup) {
}
func debug(g *gin.RouterGroup) {
g.GET("/path/*path", middlewares.Down(sign.Verify), func(ctx *gin.Context) {
rawPath := ctx.MustGet("path").(string)
ctx.JSON(200, gin.H{
g.GET("/path/*path", middlewares.Down(sign.Verify), func(c *gin.Context) {
rawPath := c.Request.Context().Value(conf.PathKey).(string)
c.JSON(200, gin.H{
"path": rawPath,
})
})
g.GET("/hide_privacy", func(ctx *gin.Context) {
common.ErrorStrResp(ctx, "This is ip: 1.1.1.1", 400)
g.GET("/hide_privacy", func(c *gin.Context) {
common.ErrorStrResp(c, "This is ip: 1.1.1.1", 400)
})
g.GET("/gc", func(c *gin.Context) {
runtime.GC()