34 lines
763 B
Go
34 lines
763 B
Go
// Package request ...
|
|
//
|
|
// Description : request ...
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 2025-05-08 14:39
|
|
package request
|
|
|
|
import (
|
|
"git.zhangdeman.cn/zhangdeman/serialize"
|
|
"github.com/tidwall/gjson"
|
|
"resty.dev/v3"
|
|
)
|
|
|
|
// WriteForm application/x-www-form-urlencoded 实现
|
|
type WriteForm struct {
|
|
}
|
|
|
|
func (w *WriteForm) Write(request *resty.Request, bodyData map[string]any) error {
|
|
if len(bodyData) == 0 {
|
|
return nil
|
|
}
|
|
bodyStr := serialize.JSON.MarshalForStringIgnoreError(bodyData)
|
|
formatBodyData := map[string]string{}
|
|
jsonObj := gjson.Parse(bodyStr)
|
|
jsonObj.ForEach(func(key, value gjson.Result) bool {
|
|
formatBodyData[key.String()] = value.String()
|
|
return true
|
|
})
|
|
request.SetFormData(formatBodyData)
|
|
return nil
|
|
}
|