goz

package module
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 19 Imported by: 2

README

goz (From goz)

A fantastic HTTP request library used in golang. Inspired by guzzle

Installation

go get -u gitee.com/teval/goz

Documentation

API documentation can be found here: https://godoc.org/github.com/idoubi/goz

Thanks

https://github.com/idoubi/goz

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Debug                bool
	NoInsecureSkipVerify bool
	NoDisableKeepAlives  bool
	BaseURI              string
	Timeout              float32

	Query      interface{}
	Headers    map[string]interface{}
	Cookies    interface{}
	FormParams map[string]interface{}
	ByteData   []byte

	// Add By Teval: multipart/form-data;
	FormData map[string]any
	JSON     interface{}
	XML      interface{}
	Proxy    string

	ParseBodyFunc func(src []byte) (dist []byte) // 自定义响应数据解密
	// contains filtered or unexported fields
}

Options object

type Request

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

Request object

func NewClient

func NewClient(opts ...Options) *Request

NewClient new request object

func (*Request) Delete

func (r *Request) Delete(uri string, opts ...Options) (*Response, error)

Delete send delete request

func (*Request) Get

func (r *Request) Get(uri string, opts ...Options) (*Response, error)

Get send get request

func (*Request) Options

func (r *Request) Options(uri string, opts ...Options) (*Response, error)

Options send options request

func (*Request) Patch

func (r *Request) Patch(uri string, opts ...Options) (*Response, error)

Patch send patch request

func (*Request) Post

func (r *Request) Post(uri string, opts ...Options) (*Response, error)

Post send post request

Example
f, _ := os.Open("./111.png")
defer f.Close()

r, err := Post("http://localhost:8021/upload", Options{
	Debug: true,
	FormData: map[string]interface{}{
		"xfile": "",
	},
})

fmt.Println(r, err)
Output:

func (*Request) Put

func (r *Request) Put(uri string, opts ...Options) (*Response, error)

Put send put request

func (*Request) Request

func (r *Request) Request(method, uri string, opts ...Options) (*Response, error)

Request send request

type Response

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

Response response object

func Delete

func Delete(uri string, opts ...Options) (*Response, error)

Delete send delete request

func Get

func Get(uri string, opts ...Options) (*Response, error)

Get send get request

func Patch

func Patch(uri string, opts ...Options) (*Response, error)

Patch send patch request

func Post

func Post(uri string, opts ...Options) (*Response, error)

Post send post request

func Put

func Put(uri string, opts ...Options) (*Response, error)

Put send put request

func (*Response) GetBody

func (r *Response) GetBody() (ResponseBody, error)

GetBody parse response body

func (*Response) GetHeader

func (r *Response) GetHeader(name string) []string

GetHeader get response header

func (*Response) GetHeaderLine

func (r *Response) GetHeaderLine(name string) string

GetHeaderLine get a single response header

func (*Response) GetHeaders

func (r *Response) GetHeaders() map[string][]string

GetHeaders get response headers

func (*Response) GetParsedBody

func (r *Response) GetParsedBody() (*gjson.Result, error)

GetParsedBody parse response body with gjson

func (*Response) GetReasonPhrase

func (r *Response) GetReasonPhrase() string

GetReasonPhrase get response reason phrase

func (*Response) GetRequest

func (r *Response) GetRequest() *http.Request

GetRequest get request object

func (*Response) GetResponse added in v1.2.4

func (r *Response) GetResponse() *http.Response

GetResponse get response object - By Teval 20231128

func (*Response) GetStatusCode

func (r *Response) GetStatusCode() int

GetStatusCode get response status code

func (*Response) HasHeader

func (r *Response) HasHeader(name string) bool

HasHeader get if header exsits in response headers

func (*Response) IsTimeout

func (r *Response) IsTimeout() bool

IsTimeout get if request is timeout

type ResponseBody

type ResponseBody []byte

ResponseBody response body

func (ResponseBody) GetContents

func (r ResponseBody) GetContents() string

GetContents format response body as string

func (ResponseBody) Read

func (r ResponseBody) Read(length int) []byte

Read get slice of response body

func (ResponseBody) String

func (r ResponseBody) String() string

String fmt outout

Jump to

Keyboard shortcuts

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