|
|
@@ -67,18 +67,20 @@ func (c *Context) GetHeader() *Header {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- header := make(map[string]string)
|
|
|
-
|
|
|
- for key, values := range c.Request.Header {
|
|
|
- header[key] = strings.Join(values, ",")
|
|
|
+ return &Header{
|
|
|
+ c: c,
|
|
|
+ header: c.ReadOriginHeader(),
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- c.Set(headerKey, header)
|
|
|
+func (c *Context) ReadOriginHeader() map[string]string {
|
|
|
+ originHeader := make(map[string]string)
|
|
|
|
|
|
- return &Header{
|
|
|
- c: c,
|
|
|
- header: header,
|
|
|
+ for key, values := range c.Request.Header {
|
|
|
+ originHeader[key] = strings.Join(values, ",")
|
|
|
}
|
|
|
+
|
|
|
+ return originHeader
|
|
|
}
|
|
|
|
|
|
// GetBytesBody 获取上下文中的字节Body
|
|
|
@@ -180,9 +182,12 @@ func (c *Context) GetJsonBody() (*JsonBody, error) {
|
|
|
func (c *Context) GetQueryParams() *QueryPrams {
|
|
|
queryParams, exist := c.Get(queryParamsKey)
|
|
|
if !exist {
|
|
|
+ originQueryParams := c.GetOriginQueryParams()
|
|
|
+ c.Set(queryParamsKey, originQueryParams)
|
|
|
+
|
|
|
return &QueryPrams{
|
|
|
c: c,
|
|
|
- queryParams: c.GetOriginQueryParams(),
|
|
|
+ queryParams: originQueryParams,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -200,6 +205,9 @@ func (c *Context) GetQueryParams() *QueryPrams {
|
|
|
func (c *Context) GetPathParams() *PathPrams {
|
|
|
pathParams, exist := c.Get(pathParamsKey)
|
|
|
if !exist {
|
|
|
+ originPathParams := c.GetOriginPathParams()
|
|
|
+ c.Set(pathParamsKey, originPathParams)
|
|
|
+
|
|
|
return &PathPrams{
|
|
|
c: c,
|
|
|
pathParams: c.GetOriginPathParams(),
|
|
|
@@ -275,6 +283,15 @@ type Header struct {
|
|
|
header map[string]string
|
|
|
}
|
|
|
|
|
|
+// Reload 从Context重新加载Header
|
|
|
+// 参数: 无
|
|
|
+// 返回值: 无
|
|
|
+func (header *Header) Reload() {
|
|
|
+ originHeader := header.c.ReadOriginHeader()
|
|
|
+ header.c.Set(headerKey, originHeader)
|
|
|
+ header.header = originHeader
|
|
|
+}
|
|
|
+
|
|
|
// Set 设置Header
|
|
|
// 参数:
|
|
|
// - key: Header的键
|
|
|
@@ -312,6 +329,21 @@ type BytesBody struct {
|
|
|
bytesBody []byte
|
|
|
}
|
|
|
|
|
|
+// Reload 从Context重新加载BytesBody
|
|
|
+// 参数: 无
|
|
|
+// 返回值:
|
|
|
+// - 错误
|
|
|
+func (bytesBody *BytesBody) Reload() error {
|
|
|
+ originBody, err := bytesBody.c.ReadOriginBody()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ bytesBody.c.Set(headerKey, originBody)
|
|
|
+ bytesBody.bytesBody = originBody
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
// Set 设置字节body
|
|
|
// 参数:
|
|
|
// - body: 字节body的内容
|
|
|
@@ -364,6 +396,27 @@ type JsonBody struct {
|
|
|
jsonBodyMap map[string]any
|
|
|
}
|
|
|
|
|
|
+// Reload 从Context重新加载JsonBody
|
|
|
+// 参数: 无
|
|
|
+// 返回值:
|
|
|
+// - 错误
|
|
|
+func (jsonBody *JsonBody) Reload() error {
|
|
|
+ bytesBody, err := jsonBody.c.ReadOriginBody()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ jsonBodyMap := make(map[string]any)
|
|
|
+ err = json.Unmarshal(bytesBody, &jsonBodyMap)
|
|
|
+ if err != nil {
|
|
|
+ return errors.New(err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ jsonBody.c.Set(bodyKey, jsonBodyMap)
|
|
|
+ jsonBody.jsonBodyMap = jsonBodyMap
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
// Set 设置JsonBody键对应的值
|
|
|
// 参数:
|
|
|
// - key: JsonBody的键
|
|
|
@@ -437,6 +490,15 @@ type QueryPrams struct {
|
|
|
queryParams map[string]string
|
|
|
}
|
|
|
|
|
|
+// Reload 从Context重新加载QueryParams
|
|
|
+// 参数: 无
|
|
|
+// 返回值: 无
|
|
|
+func (queryParams *QueryPrams) Reload() {
|
|
|
+ originQueryParams := queryParams.c.GetOriginQueryParams()
|
|
|
+ queryParams.c.Set(queryParamsKey, originQueryParams)
|
|
|
+ queryParams.queryParams = originQueryParams
|
|
|
+}
|
|
|
+
|
|
|
// Set 设置查询参数
|
|
|
// 参数:
|
|
|
// - key: 查询参数的键
|
|
|
@@ -478,6 +540,15 @@ type PathPrams struct {
|
|
|
pathParams map[string]string
|
|
|
}
|
|
|
|
|
|
+// Reload 从Context重新加载QueryParams
|
|
|
+// 参数: 无
|
|
|
+// 返回值: 无
|
|
|
+func (pathParams *PathPrams) Reload() {
|
|
|
+ originPathParams := pathParams.c.GetOriginPathParams()
|
|
|
+ pathParams.c.Set(pathParamsKey, originPathParams)
|
|
|
+ pathParams.pathParams = originPathParams
|
|
|
+}
|
|
|
+
|
|
|
// Set 设置路径参数
|
|
|
// 参数:
|
|
|
// - key: 路径参数的键
|