k3xurl

package module
v0.0.0-...-e6f74b4 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: Apache-2.0 Imports: 13 Imported by: 1

README

k3xurl: HTTP请求的封装

Documentation

Index

Constants

View Source
const (
	HeaderAccept         = "Accept"
	HeaderAcceptLanguage = "Accept-Language"
	HeaderAcceptEncoding = "Accept-Encoding"
	HeaderUserAgent      = "User-Agent"
	HeaderContentType    = "Content-Type"
	HeaderCacheControl   = "Cache-Control" // no-cache
	HeaderPragma         = "Pragma"        // no-cache
)
View Source
const (
	MethodGet     = http.MethodGet
	MethodHead    = http.MethodHead
	MethodPost    = http.MethodPost
	MethodPut     = http.MethodPut
	MethodPatch   = http.MethodPatch
	MethodDelete  = http.MethodDelete
	MethodConnect = http.MethodConnect
	MethodOptions = http.MethodOptions
	MethodTrace   = http.MethodTrace
)

Variables

This section is empty.

Functions

func NoBody

func NoBody() (contentType string, body io.Reader, err error)

NoBody 空请求体

func NoProcess

func NoProcess(*http.Response) error

NoProcess 不处理

Types

type Body

type Body = func() (contentType string, body io.Reader, err error) // 请求提交内容构造方法

一些特定方法的定义

type HeaderOption

type HeaderOption = func(headers http.Header) // 请求头处理

一些特定方法的定义

type Option

type Option = func(*Request) error // 请求选项

一些特定方法的定义

func CookieEnabled

func CookieEnabled(enabled ...bool) Option

CookieEnabled 开关 Cookie

func Jar

func Jar(jar http.CookieJar) Option

Jar 设置Cookie容器

func UseClient

func UseClient(client *http.Client) Option

UseClient 使用自定义的HTTP客户端

type Process

type Process = func(resp *http.Response) error // 响应处理器

一些特定方法的定义

func DefaultStatusCheck

func DefaultStatusCheck(next Process) Process

DefaultStatusCheck 默认状态检查,如果Status不小于400则直接报错

type ProcessMw

type ProcessMw = func(next Process) Process // 响应预处理器

一些特定方法的定义

type Request

type Request struct {
	// contains filtered or unexported fields
}

Request 请求构造

func Default

func Default(ctx context.Context) *Request

Default 默认的请求器,仅处理小于400的请求

func With

func With(ctx context.Context, options ...Option) *Request

With 以一些选项开始初始化请求器

func (*Request) BeforeProcess

func (c *Request) BeforeProcess(mws ...ProcessMw) *Request

BeforeProcess 在处理之前的预处理

func (*Request) Body

func (c *Request) Body(body Body) *Request

Body 设置请求提交内容

func (*Request) Download

func (c *Request) Download(fn string) (err error)

Download 下载到文件

func (*Request) Form

func (c *Request) Form(form url.Values) *Request

Form 提交表单

func (*Request) HeaderAdd

func (c *Request) HeaderAdd(k string, vs ...string) *Request

HeaderAdd 添加请求头

func (*Request) HeaderDel

func (c *Request) HeaderDel(keys ...string) *Request

HeaderDel 删除请求头

func (*Request) HeaderSet

func (c *Request) HeaderSet(k string, vs ...string) *Request

HeaderSet 设置请求头

func (*Request) Method

func (c *Request) Method(method string) *Request

Method 设置请求方法

func (*Request) Process

func (c *Request) Process(process Process) error

Process 处理响应

func (*Request) ProcessBytes

func (c *Request) ProcessBytes() (data []byte, err error)

ProcessBytes 处理响应字节

func (*Request) Query

func (c *Request) Query(query string) *Request

Query 设置请求Query参数

func (*Request) TryAt

func (c *Request) TryAt(times ...time.Duration) *Request

TryAt 失败重试,等待休眠时间

func (*Request) Url

func (c *Request) Url(url string) *Request

Url 设置请求链接

func (*Request) UseClient

func (c *Request) UseClient(client *http.Client) *Request

UseClient 使用的客户端定义

func (*Request) With

func (c *Request) With(options ...Option) *Request

With 增加选项

Directories

Path Synopsis
process module

Jump to

Keyboard shortcuts

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