reqs

package
v0.0.0-...-1e55a42 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultTimeout = 5 * time.Second
	DefaultClient  = &http.Client{Timeout: DefaultTimeout}
)

Functions

func BuildRequest

func BuildRequest(method string, urlstr string, body io.Reader, opts *Opts) (*http.Request, error)

BuildRequest 创建一个http请求, 合并opts中的参数到请求中, 返回请求对象和错误

func Q

func Q(kv ...string) url.Values

Types

type Opts

type Opts struct {
	Timeout        time.Duration
	Headers        map[string]string
	Cookies        map[string]string
	Query          url.Values
	Stream         bool
	AllowRedirects bool
	// contains filtered or unexported fields
}

func (*Opts) AddCookie

func (o *Opts) AddCookie(cookie *http.Cookie) *Opts

type Resp

type Resp struct {
	http.Response
	Error error
}

Resp is the response of a request

func Do

func Do(method string, url string, body io.Reader, opts *Opts) *Resp

func Get

func Get(url string) *Resp

Get performs an HTTP GET request to the specified URL and returns a pointer to a Resp struct containing the response and any error encountered.

func Get2

func Get2(url string, opts *Opts) *Resp

Get2 performs an HTTP GET request to the specified URL with the given options and returns a pointer to a Resp struct containing the response and any error encountered.

func Post2

func Post2(url string, body io.Reader, opts *Opts) *Resp

Post2 performs an HTTP POST request to the specified URL with the given body and options and returns a pointer to a Resp struct containing the response and any error encountered.

func PostFiles

func PostFiles(url string, files map[string]string) *Resp

PostFiles performs an HTTP POST request to the specified URL with a multipart/form-data body and returns a pointer to a Resp struct containing the response and any error encountered. The files map is a map of field names and file paths. The file paths can start with "@" to indicate a file path.

func PostFiles2

func PostFiles2(url string, files map[string]string, opts *Opts) *Resp

func PostJSON

func PostJSON(url string, body any) *Resp

PostJSON performs an HTTP POST request to the specified URL with a JSON body and returns a pointer to a Resp struct containing the response and any error encountered.

func (*Resp) Bytes

func (r *Resp) Bytes() ([]byte, error)

func (*Resp) Close

func (r *Resp) Close() error

func (*Resp) JSON

func (r *Resp) JSON(v any) error

func (*Resp) JSONMap

func (r *Resp) JSONMap() (map[string]any, error)

func (*Resp) String

func (r *Resp) String() (string, error)

Jump to

Keyboard shortcuts

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