requests

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(baseProfile string, opts ...client.Option) error

func RegisterProfile

func RegisterProfile(name string, p []client.Option)

Types

type Client

type Client = client.Client

func NewClient

func NewClient(opts ...client.Option) (*Client, error)

func NewClientWithProfile

func NewClientWithProfile(baseProfile string, opts ...client.Option) (*Client, error)

type ClientOption

type ClientOption = client.Option

type Handler added in v0.2.0

type Handler = client.Handler

type Middleware added in v0.2.0

type Middleware = client.Middleware
Example
cli, _ := NewClient()
cli.Use(func(next Handler) Handler {
	return func(rc *RequestCtx) error {
		if rc.Request.Headers == nil {
			rc.Request.Headers = make(http.Header)
		}
		rc.Request.Headers.Add("handler-ok", "1")
		err := next(rc)
		if err == nil {
			fmt.Println(rc.Response.Header.Get("Date"))
		}
		return err
	}
})
done, resp, err := cli.CtxDo(context.Background(), request.Get("https://www.google.com", nil))
if err != nil {
	panic(err)
}
defer done()

c, err := resp.Body()
fmt.Println(string(c))
Output:

type Request

type Request = request.Request

type RequestCtx added in v0.2.0

type RequestCtx = client.RequestCtx

type Response

type Response = response.Response

func CtxDo

func CtxDo(ctx context.Context, req *Request) (func(), *Response, error)
Example
done, resp, err := CtxDo(context.Background(), request.Get("https://www.google.com", nil))
if err != nil {
	panic(err)
}
defer done()
fmt.Println(resp.Header.Get("Date"))
c, err := resp.Body()
fmt.Println(string(c))
Output:

Directories

Path Synopsis
internal
profiles
package profiles defines sets of default configurations that pipo uses for requesting in http protocol.
package profiles defines sets of default configurations that pipo uses for requesting in http protocol.
request/form
package form implements form encoder
package form implements form encoder

Jump to

Keyboard shortcuts

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