greq

package module
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 17 Imported by: 5

README

restful web service client

Go Report Card Build Status

restful web service reqeust tool

Requirements

Install

go get github.com/syhlion/greq

Usage

func main(){

    //need import https://github.com/syhlion/requestwork.v2
    worker:=requestwork.New(50)
    debug:=true

    client:=greq.New(worker,15*time.Second,debug)

    //GET
    data,httpstatus,err:=client.Get("https://tw.yahoo.com",nil)

    //POST
    v := url.Values{}
    v.Add("data", string(data))
    data,httpstatus,err:=client.Post("https://tw.yahoo.com",bytes.NewBufferString(v.Encode()))

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client instance

func New

func New(worker *requestwork.Worker, timeout time.Duration, debug bool) *Client

New return http client

func (*Client) CheckRedircet added in v1.0.6

func (c *Client) CheckRedircet(f func(req *http.Request, via []*http.Request) error)

func (*Client) Delete

func (c *Client) Delete(url string, params url.Values) (data []byte, httpstatus int, err error)

Delete http method Delete

func (*Client) DeleteRaw added in v1.1.0

func (c *Client) DeleteRaw(url string, body io.Reader) (data []byte, httpstatus int, err error)

func (*Client) DeleteRawWithOnceHeader added in v1.1.0

func (c *Client) DeleteRawWithOnceHeader(url string, body io.Reader, headers map[string]string) (data []byte, httpstatus int, err error)

func (*Client) DeleteWithOnceHeader

func (c *Client) DeleteWithOnceHeader(url string, params url.Values, headers map[string]string) (data []byte, httpstatus int, err error)

func (*Client) Get

func (c *Client) Get(url string, params url.Values) (data []byte, httpstatus int, err error)

Get http method get

func (*Client) GetWithOnceHeader

func (c *Client) GetWithOnceHeader(url string, params url.Values, headers map[string]string) (data []byte, httpstatus int, err error)

func (*Client) Post

func (c *Client) Post(url string, params url.Values) (data []byte, httpstatus int, err error)

Post http method post

func (*Client) PostRaw added in v1.0.5

func (c *Client) PostRaw(url string, body io.Reader) (data []byte, httpstatus int, err error)

func (*Client) PostRawWithOnceHeader added in v1.0.5

func (c *Client) PostRawWithOnceHeader(url string, body io.Reader, headers map[string]string) (data []byte, httpstatus int, err error)

func (*Client) PostWithOnceHeader

func (c *Client) PostWithOnceHeader(url string, params url.Values, headers map[string]string) (data []byte, httpstatus int, err error)

func (*Client) Put

func (c *Client) Put(url string, params url.Values) (data []byte, httpstatus int, err error)

Put http method put

func (*Client) PutRaw added in v1.0.6

func (c *Client) PutRaw(url string, body io.Reader) (data []byte, httpstatus int, err error)

func (*Client) PutRawWithOnceHeader added in v1.1.0

func (c *Client) PutRawWithOnceHeader(url string, body io.Reader, headers map[string]string) (data []byte, httpstatus int, err error)

func (*Client) PutWithOnceHeader

func (c *Client) PutWithOnceHeader(url string, params url.Values, headers map[string]string) (data []byte, httpstatus int, err error)

func (*Client) ResolveRequest added in v1.0.6

func (c *Client) ResolveRequest(req *http.Request, params url.Values, e error) (data []byte, httpstatus int, err error)

func (*Client) ResolveTraceRequest added in v1.1.2

func (c *Client) ResolveTraceRequest(req *http.Request, trace *httptrace.ClientTrace) (data []byte, httpstatus int, err error)

ResolveTraceRequest 自定義 httptrace

func (*Client) SetBasicAuth

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

SetBasicAuth set Basic auth

func (*Client) SetHeader

func (c *Client) SetHeader(key, value string) *Client

SetHeader set http header

func (*Client) SetHost

func (c *Client) SetHost(host string) *Client

SetHost set host

type Trace

type Trace struct {
	Url              string        `json:"url"`
	Method           string        `json:"method"`
	Body             string        `json:"body"`
	Param            string        `json:"param"`
	DNSLookup        time.Duration `json:"dns_lookup"`
	TCPConnection    time.Duration `json:"tcp_connection"`
	TLSHandshake     time.Duration `json:"tls_handshake"`
	ServerProcessing time.Duration `json:"server_prcoessing"`
	ContentTransfer  time.Duration `json:"content_transfer"`
	NameLookup       time.Duration `json:"name_lookup"`
	Connect          time.Duration `json:"connect"`
	PreTransfer      time.Duration `json:"pre_transfer"`
	StartTransfer    time.Duration `json:"start_transfer"`
	Total            time.Duration `json:"total"`
}

Jump to

Keyboard shortcuts

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