2024-10-22 16:49:45 +08:00
|
|
|
// Package parse_body ...
|
|
|
|
//
|
|
|
|
// Description : parse_body ...
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 2024-10-22 16:42
|
|
|
|
package parse_body
|
2024-10-22 17:14:53 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"git.zhangdeman.cn/zhangdeman/consts"
|
|
|
|
"git.zhangdeman.cn/zhangdeman/serialize"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
type JsonAdaptor struct {
|
|
|
|
base
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse 解析json请求体
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 17:13 2024/10/22
|
|
|
|
func (j JsonAdaptor) Parse(ctx *gin.Context, receiver any) ([]byte, error) {
|
|
|
|
unmarshalFunc := j.Unmarshal()
|
|
|
|
if nil == unmarshalFunc {
|
|
|
|
unmarshalFunc = serialize.JSON.UnmarshalWithNumber
|
|
|
|
}
|
|
|
|
return j.DoParse(ctx, receiver, unmarshalFunc)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal 指定解析方法
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 16:56 2024/10/22
|
|
|
|
func (j JsonAdaptor) Unmarshal() func(sourceData []byte, receiver any) error {
|
|
|
|
return serialize.JSON.UnmarshalWithNumber
|
|
|
|
}
|
|
|
|
|
|
|
|
// ContentType 请求类型固定返回json
|
|
|
|
//
|
|
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
|
|
//
|
|
|
|
// Date : 16:59 2024/10/22
|
|
|
|
func (j JsonAdaptor) ContentType() string {
|
|
|
|
return consts.MimeTypeJson
|
|
|
|
}
|