simpleRequest/body.go
2022-12-10 02:08:17 +08:00

56 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @FileName: body.go
* @Author: JJXu
* @CreateTime: 2022/3/2 上午1:23
* @Description:
*/
package simpleRequest
// EntryMark 请求体条目标记用于标记输入的body内容格式
type EntryMark string
func (b EntryMark) string() string {
return string(b)
}
const (
StringEntryType EntryMark = "__STRING_ENTRY__"
BytesEntryType EntryMark = "__BYTES_ENTRY__"
ModelEntryType EntryMark = "__MODEL_ENTRY__"
MapEntryType EntryMark = "__MAP_ENTRY__"
)
type BodyConf struct {
simpleReq *SimpleRequest
}
func (s *BodyConf) Set(key string, value any) *BodyConf {
s.simpleReq.BodyEntries[key] = value
return s
}
func (s *BodyConf) Sets(data map[string]any) *BodyConf {
s.simpleReq.BodyEntryMark = MapEntryType
for k, v := range data {
s.simpleReq.BodyEntries[k] = v
}
return s
}
func (s *BodyConf) SetString(strData string) *BodyConf {
s.simpleReq.BodyEntryMark = StringEntryType
s.simpleReq.BodyEntries[StringEntryType.string()] = strData
return s
}
func (s *BodyConf) SetBytes(byteData []byte) *BodyConf {
s.simpleReq.BodyEntryMark = BytesEntryType
s.simpleReq.BodyEntries[BytesEntryType.string()] = byteData
return s
}
func (s *BodyConf) SetModel(model any) *BodyConf {
s.simpleReq.BodyEntryMark = ModelEntryType
s.simpleReq.BodyEntries[ModelEntryType.string()] = model
return s
}