增加解析header + 解析 cookie

This commit is contained in:
白茶清欢 2024-09-23 17:06:49 +08:00
parent c4d41a9d4e
commit 9d0f74b19a

View File

@ -254,3 +254,39 @@ func (wh *wrapperHandle) GetCtxIntData(ctx *gin.Context, key string, defaultVal
}
return ctx.GetInt64(key)
}
// ParseHeader 解析header数据
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:04 2024/9/23
func (wh *wrapperHandle) ParseHeader(ctx *gin.Context) map[string]string {
headerData := map[string]string{}
if nil == ctx || nil == ctx.Request {
return headerData
}
for headerName, headerVal := range ctx.Request.Header {
if len(headerVal) > 0 {
headerData[headerName] = headerVal[0]
} else {
headerData[headerName] = ""
}
}
return headerData
}
// ParseCookie 解析cookie数据
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 17:06 2024/9/23
func (wh *wrapperHandle) ParseCookie(ctx *gin.Context) map[string]string {
cookieData := map[string]string{}
if nil == ctx || nil == ctx.Request {
return cookieData
}
for _, itemCookie := range ctx.Request.Cookies() {
cookieData[itemCookie.Name] = itemCookie.Value
}
return cookieData
}