Documentation
¶
Index ¶
- Variables
- func AddCookie(req *http.Request, val reflect.Value, cookie []reflect.StructField)
- func AddHeader(req *http.Request, val reflect.Value, header []reflect.StructField)
- func AddQuery(req *http.Request, val reflect.Value, query []reflect.StructField)
- func AddValue(ctx context.Context, val reflect.Value, field reflect.StructField, ...)
- func CamelToHyphenated(s string) string
- func CamelToSnake(s string) string
- func MakeJSONMap(ctx context.Context, val reflect.Value, body []reflect.StructField) map[string]any
- func MakeURLValues(ctx context.Context, val reflect.Value, fields []reflect.StructField) url.Values
- func Marshal(i any) string
- func NewJSONReader(v any) (io.Reader, error)
- func PreloadTask(api ...any)
- func TypePtr(in any) uintptr
- func Unmarshal(value reflect.Value, s string) (any, error)
- func ValuePtr(in any) uintptr
- type APIBody
- type APICookie
- type APICustom
- type APIHeader
- type APIQuery
- type APIXSRF
- type Emptyface
- type Get
- type Marshaler
- type PostForm
- type PostJSON
- type PostMultipartForm
- type Task
Constants ¶
This section is empty.
Variables ¶
View Source
var ( NameReplacer = CamelToSnake HeaderReplacer = CamelToHyphenated )
Functions ¶
func AddValue ¶
func AddValue(ctx context.Context, val reflect.Value, field reflect.StructField, add func(string, string))
AddValue 根据提供的 StructField 添加对应的值
func CamelToHyphenated ¶
CamelToHyphenated 将字符串中的大写字母替换为横杠加大写字母,大写首字母前不添加横杠,连续的大写字母只在第一个字母前添加横杠
func CamelToSnake ¶
CamelToSnake 将字符串中的大写字母替换为下划线加小写字母,大写首字母前不添加下划线,连续的大写字母只在第一个字母前添加下划线
func MakeJSONMap ¶
MakeJSONMap 根据提供的 []StructField 制作 map[string]any
func MakeURLValues ¶
MakeURLValues 根据提供的 []StructField 制作 url.Values
func NewJSONReader ¶
NewJSONReader 将提供的值序列化后存入 *bytes.Buffer
Types ¶
type APIBody ¶
type APIBody interface {
Body(r *http.Request, value reflect.Value, body []reflect.StructField) (io.Reader, error)
}
API 请求体
type APICookie ¶
type APICookie interface {
Cookie(r *http.Request, value reflect.Value, cookie []reflect.StructField) error
}
API Cookie
type APICustom ¶
type APICustom interface {
Custom(r *http.Request, value reflect.Value, custom map[string][]reflect.StructField) error
}
API 自定义标签
type APIHeader ¶
type APIHeader interface {
Header(r *http.Request, value reflect.Value, header []reflect.StructField) error
}
API 请求头
type APIQuery ¶
type APIQuery interface {
Query(r *http.Request, value reflect.Value, query []reflect.StructField) error
}
API 请求参数
type PostForm ¶
type PostForm struct {
ContentType string `req:"header" default:"application/x-www-form-urlencoded"`
}
以 Form 表单为请求体的 POST 请求构造器
type PostJSON ¶
type PostJSON struct {
ContentType string `req:"header" default:"application/json"`
}
以 JSON 为请求体的 POST 请求构造器
type PostMultipartForm ¶
type PostMultipartForm struct {
ContentType string `req:"header" default:"$ContentType"`
}
以多部份 Form 表单为请求体的 POST 请求构造器
func (PostMultipartForm) Body ¶
func (PostMultipartForm) Body(req *http.Request, value reflect.Value, body []reflect.StructField) (io.Reader, error)
func (PostMultipartForm) Method ¶
func (PostMultipartForm) Method() string
type Task ¶
type Task struct {
Body []reflect.StructField
Query []reflect.StructField
Header []reflect.StructField
Cookie []reflect.StructField
Custom map[string][]reflect.StructField // 自定义标签
}
请求任务
包含了 API 结构体中所有有效字段信息
Click to show internal directories.
Click to hide internal directories.