curl

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package curl 封装go 标准http 库使其支持类似curl 的调用

Index

Constants

View Source
const (
	GET     = "GET"
	POST    = "POST"
	PUT     = "PUT"
	PATCH   = "PATCH"
	DELETE  = "DELETE"
	HEAD    = "HEAD"
	OPTIONS = "OPTIONS"
)

定义一些基本的curl 请求方法常量映射

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client curl client 对象

func NewClient

func NewClient() *Client

NewClient 新建一个 curl 客户端

func (*Client) EnableCookie added in v0.4.2

func (c *Client) EnableCookie()

EnableCookie let client auto save cookie in every request

func (*Client) Fetch

func (c *Client) Fetch(request *Request) (*Response, error)

Fetch 执行request 请求

func (*Client) WithBaseURL

func (c *Client) WithBaseURL(baseurl string) error

WithBaseURL 设置client 的 base url

type Request

type Request struct {
	Raw *http.Request
}

Request Request

func NewRequest

func NewRequest(method, url string) (*Request, error)

NewRequest 新建一个curl 请求

func (*Request) SetHeader

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

SetHeader 设置请求头

func (*Request) String

func (r *Request) String() string

String request stringfy

func (*Request) WithBasicAuth

func (r *Request) WithBasicAuth(username, passwd string) error

WithBasicAuth 添加basic auth 认证

func (*Request) WithBearerAuth

func (r *Request) WithBearerAuth(token string) error

WithBearerAuth 添加 bearer auth 认证

func (*Request) WithJSONBody

func (r *Request) WithJSONBody(content interface{}) error

WithJSONBody 添加一个json 请求体

func (*Request) WithQuery

func (r *Request) WithQuery(v *url.Values) error

WithQuery 在request 中添加query

type Response

type Response struct {
	Raw  *http.Response
	Body []byte
}

Response 返回对象

func (*Response) ParseBody

func (r *Response) ParseBody(v interface{}) error

ParseBody 根据 response 的 content-type 自动解析返回结果

func (*Response) ParseJSONBody

func (r *Response) ParseJSONBody(v interface{}) error

ParseJSONBody 将返回body 作为JSON 解析

func (*Response) String

func (r *Response) String() string

String Stringer implement

Jump to

Keyboard shortcuts

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