method

package
v0.0.0-...-b912de2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NameReplacer   = CamelToSnake
	HeaderReplacer = CamelToHyphenated
)

Functions

func AddCookie

func AddCookie(req *http.Request, val reflect.Value, cookie []reflect.StructField)

AddCookie 向 req 请求添加 Cookie

func AddHeader

func AddHeader(req *http.Request, val reflect.Value, header []reflect.StructField)

AddHeader 向 req 请求添加请求头

func AddQuery

func AddQuery(req *http.Request, val reflect.Value, query []reflect.StructField)

AddQuery 向 req 请求添加请求参数

func AddValue

func AddValue(ctx context.Context, val reflect.Value, field reflect.StructField, add func(string, string))

AddValue 根据提供的 StructField 添加对应的值

func CamelToHyphenated

func CamelToHyphenated(s string) string

CamelToHyphenated 将字符串中的大写字母替换为横杠加大写字母,大写首字母前不添加横杠,连续的大写字母只在第一个字母前添加横杠

func CamelToSnake

func CamelToSnake(s string) string

CamelToSnake 将字符串中的大写字母替换为下划线加小写字母,大写首字母前不添加下划线,连续的大写字母只在第一个字母前添加下划线

func MakeJSONMap

func MakeJSONMap(ctx context.Context, val reflect.Value, body []reflect.StructField) map[string]any

MakeJSONMap 根据提供的 []StructField 制作 map[string]any

func MakeURLValues

func MakeURLValues(ctx context.Context, val reflect.Value, fields []reflect.StructField) url.Values

MakeURLValues 根据提供的 []StructField 制作 url.Values

func Marshal

func Marshal(i any) string

Marshal 将任意类型转换为字符串

func NewJSONReader

func NewJSONReader(v any) (io.Reader, error)

NewJSONReader 将提供的值序列化后存入 *bytes.Buffer

func PreloadTask

func PreloadTask(api ...any)

PreloadTask 预加载多个 API 的请求任务到缓存中

func TypePtr

func TypePtr(in any) uintptr

TypePtr 获取任意类型变量的类型指针,用于唯一标识该类型

func Unmarshal

func Unmarshal(value reflect.Value, s string) (any, error)

Unmarshal 将字符串转换为指定类型的值

func ValuePtr

func ValuePtr(in any) uintptr

ValuePtr 获取任意类型变量的值指针,用于唯一标识该变量

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 APIXSRF

type APIXSRF interface {
	XSRF() (xsrfCookieName, xsrfHeaderName string)
}

XSRF 请求头

type Emptyface

type Emptyface struct {
	Type  unsafe.Pointer
	Value unsafe.Pointer
}

Emptyface 是空接口的内部表示,用于获取类型和值指针

type Get

type Get struct{}

GET 请求构造器

直接嵌入结构体即可使用

func (Get) Method

func (Get) Method() string

type Marshaler

type Marshaler interface {
	MarshalString() string
}

Marshaler 用于将类型转换为字符串

type PostForm

type PostForm struct {
	ContentType string `req:"header" default:"application/x-www-form-urlencoded"`
}

以 Form 表单为请求体的 POST 请求构造器

func (PostForm) Body

func (PostForm) Body(req *http.Request, value reflect.Value, body []reflect.StructField) (io.Reader, error)

func (PostForm) Method

func (PostForm) Method() string

type PostJSON

type PostJSON struct {
	ContentType string `req:"header" default:"application/json"`
}

以 JSON 为请求体的 POST 请求构造器

func (PostJSON) Body

func (PostJSON) Body(req *http.Request, value reflect.Value, body []reflect.StructField) (io.Reader, error)

func (PostJSON) Method

func (PostJSON) Method() string

type PostMultipartForm

type PostMultipartForm struct {
	ContentType string `req:"header" default:"$ContentType"`
}

以多部份 Form 表单为请求体的 POST 请求构造器

func (PostMultipartForm) Body

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 结构体中所有有效字段信息

func LoadTask

func LoadTask(api any) Task

LoadTask 根据 API 加载请求任务,如果缓存中不存在则创建新任务并存入缓存

func NewTask

func NewTask(v any) (task Task)

NewTask 根据给定的结构体类型生成请求任务

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL