fix(context): make context Value method adhere to Go standards (#3897)

This commit is contained in:
Farmer.Chillax
2024-03-21 21:08:41 +08:00
committed by GitHub
parent 0d9dbbb445
commit 2b1da2b0b3
2 changed files with 6 additions and 2 deletions

View File

@ -43,6 +43,10 @@ const BodyBytesKey = "_gin-gonic/gin/bodybyteskey"
// ContextKey is the key that a Context returns itself for.
const ContextKey = "_gin-gonic/gin/contextkey"
type ContextKeyType int
const ContextRequestKey ContextKeyType = 0
// abortIndex represents a typical value used in abort functions.
const abortIndex int8 = math.MaxInt8 >> 1
@ -1225,7 +1229,7 @@ func (c *Context) Err() error {
// if no value is associated with key. Successive calls to Value with
// the same key returns the same result.
func (c *Context) Value(key any) any {
if key == 0 {
if key == ContextRequestKey {
return c.Request
}
if key == ContextKey {