rest

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACCEPT_HEADER           = "Accept"
	CONTENT_TYPE_HEADER     = "Content-Type"
	CONTENT_ENCODING_HEADER = "Content-Encoding"
	AUTHORIZATION_HEADER    = "Authorization"
)

Variables

View Source
var MethodMap = map[Method]string{
	GET:     "GET",
	POST:    "POST",
	HEAD:    "HEAD",
	PUT:     "PUT",
	DELETE:  "DELETE",
	CONNECT: "CONNECT",
	OPTIONS: "OPTIONS",
	TRACE:   "TRACE",
	PATCH:   "PATCH",
}

Functions

func CustomDialContext added in v0.5.2

func CustomDialContext(dnsResolver string) func(ctx context.Context, network, address string) (net.Conn, error)

func HeaderFilterFlags

func HeaderFilterFlags(content string) string

func NewDefaultHeader

func NewDefaultHeader() http.Header

Types

type AuthType

type AuthType string
const (
	BearerToken AuthType = "bearer_token"
	BasicAuth   AuthType = "basic_auth"
)

type Client

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

func NewDefaultClient

func NewDefaultClient() *Client

func NewLogLevelClient

func NewLogLevelClient(level logger.Level) *Client

func (*Client) Clone

func (c *Client) Clone() *Client

方便重复利用

func (*Client) Delete

func (c *Client) Delete(path string) *Request

Delete begins a DELETE request. Short for c.Verb("DELETE").

func (*Client) Get

func (c *Client) Get(path string) *Request

Get begins a GET request. Short for c.Verb("GET").

func (*Client) Group

func (c *Client) Group(urlPath string) *Client

方便重复利用

func (*Client) Method

func (c *Client) Method(verb Method) *Request

func (*Client) Patch

func (c *Client) Patch(path string) *Request

Patch begins a PATCH request. Short for c.Verb("Patch").

func (*Client) Post

func (c *Client) Post(path string) *Request

Post begins a POST request. Short for c.Verb("POST").

func (*Client) Put

func (c *Client) Put(path string) *Request

Put begins a PUT request. Short for c.Verb("PUT").

func (*Client) SetBaseURL

func (c *Client) SetBaseURL(u string) *Client

修改基础路径

func (*Client) SetBasicAuth

func (c *Client) SetBasicAuth(username, password string) *Client

func (*Client) SetBearerTokenAuth

func (c *Client) SetBearerTokenAuth(token string) *Client

func (*Client) SetCarryCookies

func (c *Client) SetCarryCookies() *Client

自动携带cookie

func (*Client) SetCarryQueryParameters

func (c *Client) SetCarryQueryParameters(severity Severity) *Client

设置当跳转的时候,自动携带请求参数

func (*Client) SetCert

func (c *Client) SetCert(caPath, clientCrtPath, clientKeyPath string) *Client

设置证书

func (*Client) SetContentType

func (c *Client) SetContentType(contentType string) *Client

设置Content-Type

func (*Client) SetCookie

func (c *Client) SetCookie(cs ...*http.Cookie) *Client

设置cookie

func (*Client) SetDNS added in v0.5.2

func (c *Client) SetDNS(dnsResolver string) *Client

func (*Client) SetHeader

func (c *Client) SetHeader(key string, values ...string) *Client

设置header

func (*Client) SetIgnoreCert

func (c *Client) SetIgnoreCert() *Client

设置忽略证书

func (*Client) SetLogDirPath

func (c *Client) SetLogDirPath(path string) *Client

func (*Client) SetLogLevel

func (c *Client) SetLogLevel(l logger.Level) *Client

func (*Client) SetLogSaveFile

func (c *Client) SetLogSaveFile(s bool) *Client

func (*Client) SetMinVersionTLS

func (c *Client) SetMinVersionTLS(tlsVersion uint16) *Client

设置TLS最低版本

func (*Client) SetNoAutoRedirect

func (c *Client) SetNoAutoRedirect() *Client

禁止在遇到3XX返回码时自动跳转

func (*Client) SetProxyAdd

func (c *Client) SetProxyAdd(add string) *Client

func (*Client) SetProxyPort

func (c *Client) SetProxyPort(port int) *Client

func (*Client) SetProxyScheme

func (c *Client) SetProxyScheme(scheme string) *Client

func (*Client) SetProxyUrl

func (c *Client) SetProxyUrl(u string) *Client

设置代理

func (*Client) SetTimeout

func (c *Client) SetTimeout(t time.Duration) *Client

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(user_agent string) *Client

type Method

type Method int8
const (
	GET Method = iota
	POST
	HEAD
	PUT
	DELETE
	CONNECT
	OPTIONS
	TRACE
	PATCH
)

func (Method) MarshalJSON

func (s Method) MarshalJSON() ([]byte, error)

func (Method) String

func (s Method) String() string

func (*Method) UnmarshalJSON

func (s *Method) UnmarshalJSON(data []byte) error

type Request

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

func NewRequest

func NewRequest(c *Client) *Request

func (*Request) AbsURL

func (r *Request) AbsURL(p string) *Request

设置请求的URL的绝对路径

func (*Request) Body

func (r *Request) Body(v any) *Request

TODO 待改进

func (*Request) Cookie

func (r *Request) Cookie(cs ...*http.Cookie) *Request

设置cookie

func (*Request) DataJs

func (r *Request) DataJs(data any) *Request

设置json数据

func (*Request) Do

func (r *Request) Do(ctx context.Context) *Response

func (*Request) FormData

func (r *Request) FormData(key, value string) *Request

设置单纯表单数据

func (*Request) Header

func (r *Request) Header(key string, values ...string) *Request

请求阶段也可以设置

func (*Request) Method

func (r *Request) Method(method Method) *Request

设置请求方法

func (*Request) MultiFormData

func (r *Request) MultiFormData(key string, values ...string) *Request

提交多种内容的表单 当上传文件的同时提交表单需要用这个方法

func (*Request) Param

func (r *Request) Param(paramName, value string) *Request

添加查询参数

func (*Request) Prefix

func (r *Request) Prefix(segments ...string) *Request

设置前缀路径,但是会接在前面的前缀路径后面 使用AbsPath会直接清空前缀路径,而使用AbsPath中的路径

func (*Request) RowText

func (r *Request) RowText(t string) *Request

设置文本数据

func (*Request) SetCarryCookies

func (r *Request) SetCarryCookies() *Request

自动携带cookie

func (*Request) SetCarryQueryParameters

func (r *Request) SetCarryQueryParameters(severity Severity) *Request

设置当跳转的时候,自动携带请求参数 severity是程度

func (*Request) SetCert

func (r *Request) SetCert(caPath, clientCrtPath, clientKeyPath string) *Request

设置证书

func (*Request) SetDNS added in v0.5.2

func (r *Request) SetDNS(dnsResolver string) *Request

func (*Request) SetIgnoreCert

func (r *Request) SetIgnoreCert() *Request

设置忽略证书

func (*Request) SetMinVersionTLS

func (r *Request) SetMinVersionTLS(tlsVersion uint16) *Request

设置TLS最低版本

func (*Request) SetNoAutoRedirect

func (r *Request) SetNoAutoRedirect() *Request

禁止在遇到3XX返回码时自动跳转

func (*Request) SetProxyAdd

func (r *Request) SetProxyAdd(add string) *Request

func (*Request) SetProxyPort

func (r *Request) SetProxyPort(port int) *Request

func (*Request) SetProxyScheme

func (r *Request) SetProxyScheme(scheme string) *Request

func (*Request) SetProxyUrl

func (r *Request) SetProxyUrl(u string) *Request

设置代理

func (*Request) Suffix

func (r *Request) Suffix(segments ...string) *Request

设置后缀部分,最后会接在前缀的后面

func (*Request) TarFiles

func (r *Request) TarFiles(
	folderPath string,
	fileWhitelist,
	dirWhitelist,
	fileBlacklist,
	dirBlacklist []string,
) *Request

为docker远程传输数据实现

func (*Request) Timeout

func (r *Request) Timeout(d time.Duration) *Request

请求阶段也可以设置超时时长,如果客户端也设置了,就会覆盖客户端设置的超时时长

func (*Request) URL

func (r *Request) URL(p string) *Request

设置url为reqPath

func (*Request) UploadFiles

func (r *Request) UploadFiles(fileKey string, filePath string) *Request

上传文件

type Response

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

func NewResponse

func NewResponse(c *Client) *Response

func (*Response) Cookies

func (r *Response) Cookies() []*http.Cookie

获取响应的cookie

func (*Response) Encoding

func (r *Response) Encoding() string

获取响应的编码类型

func (*Response) Error

func (r *Response) Error() error

不处理返回, 直接判断请求是否正常

func (*Response) GetHeader

func (r *Response) GetHeader(key string) string

非链式获取header,直接返回header的key对应的value

func (*Response) Header

func (r *Response) Header(header string, v *string) *Response

链式获取header 通过传入一个header的key和接收的字符串指针,返回的对应value是在传入的字符串指针中

func (*Response) Headers

func (r *Response) Headers() http.Header

获取所有的header

func (*Response) Into

func (r *Response) Into(v any) error

TODO待改进

func (*Response) Raw

func (r *Response) Raw() ([]byte, error)

请求正常的情况下, 获取返回的数据, 不做解析,以byte[]形式返回

func (*Response) Status

func (r *Response) Status() string

获取相应状态

func (*Response) StatusCode

func (r *Response) StatusCode() int

获取相应状态码

func (*Response) Text

func (r *Response) Text() string

获取文本格式的body

func (*Response) Url

func (r *Response) Url() *url.URL

获取URL

type Severity

type Severity int8
const (
	// 必须与url的path完全相同
	FullMatch Severity = iota
	// 只需要host部分相同
	HOSTONLY
	// 所有url都可以
	All
)

type User

type User struct {
	Username string
	Password string
}

Jump to

Keyboard shortcuts

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