From 9d0f74b19add2763ffa60452a9ac8860c776351d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 23 Sep 2024 17:06:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=A7=A3=E6=9E=90header=20+?= =?UTF-8?q?=20=E8=A7=A3=E6=9E=90=20cookie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- request/wrapper.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/request/wrapper.go b/request/wrapper.go index fdfcd16..8717e7f 100644 --- a/request/wrapper.go +++ b/request/wrapper.go @@ -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 +}