requests

package module
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 16 Imported by: 3

README

Requests

Go HTTP Client Library

Usage

// New Request
r := NewRequest(WithTimout(time.Second))

// New Session
r := NewSession(WithTimout(time.Second))

// do http method
r.Get(url, map[string]string{})
r.Post(url, map[string]interface{}{})
r.Post(url, map[string]interface{}{})
r.PostFrom(url, map[string]string{})
r.Put(url, map[string]interface{}{})
r.Delete(url, map[string]interface{}{})

// download
r.Download(filePath, originUrl)
r.DownloadWithRateLimit(filePath, originUrl, rate)

// upload
r.Upload(originUrl, map[string]string{}, filepath1, filepath2 ...)

// response
r.Content()
r.ContentToString()
r.Status() // status code, status
r.Resp() // raw http.Response

Documentation

Index

Constants

View Source
const (
	ProxyHttp  = "http"
	ProxySocks = "socks5"
)
View Source
const (
	ContentTypeJson = "application/json;charset=utf-8"
	ContentTypeForm = "application/x-www-form-urlencoded"
)

Variables

View Source
var (
	DefaultTransport = NewTransport()
	DefaultClient    = NewClient()
)

Functions

func NewClient added in v1.2.12

func NewClient() *http.Client

func NewTransport added in v1.2.12

func NewTransport() *http.Transport

NewTransport is clone of http.DefaultTransport

func ProxyFromEnvironment added in v1.2.3

func ProxyFromEnvironment(req *http.Request) (*url.URL, error)

ProxyFromEnvironment read proxy form env for every request http.ProxyFromEnvironment read only once

Types

type Option added in v1.1.5

type Option func(*Request)

func WithBasicAuth added in v1.1.5

func WithBasicAuth(username, password string) Option

func WithBearerTokenAuth added in v1.1.5

func WithBearerTokenAuth(token string) Option

func WithClient added in v1.2.10

func WithClient(client *http.Client) Option

func WithDefaultClient added in v1.2.10

func WithDefaultClient() Option

func WithDefaultTransport added in v1.2.10

func WithDefaultTransport() Option

func WithHeader added in v1.1.5

func WithHeader(headers ...map[string]string) Option

func WithProxyEnv added in v1.2.12

func WithProxyEnv(proxy Proxy) Option

func WithProxyFunc added in v1.2.7

func WithProxyFunc(f func(*http.Request) (*url.URL, error)) Option

func WithProxyUrl added in v1.2.12

func WithProxyUrl(proxy *url.URL) Option

func WithSkipTLS added in v1.2.12

func WithSkipTLS() Option

func WithTimeout added in v1.1.5

func WithTimeout(t time.Duration) Option

func WithTransport added in v1.2.4

func WithTransport(tr http.RoundTripper) Option

func WithUnsetProxy added in v1.2.6

func WithUnsetProxy() Option

type Proxy added in v1.2.8

type Proxy map[string]string

func NewHttpProxy added in v1.2.8

func NewHttpProxy(proxy string) Proxy

func NewHttpProxyWithAuth added in v1.2.8

func NewHttpProxyWithAuth(proxy, username, password string) Proxy

func NewSocksProxy added in v1.2.8

func NewSocksProxy(proxy string) Proxy

func NewSocksProxyWithAuth added in v1.2.8

func NewSocksProxyWithAuth(proxy, username, password string) Proxy

type Request added in v1.0.2

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

func NewRequest added in v1.0.2

func NewRequest(options ...Option) *Request

func NewSession

func NewSession(options ...Option) *Request

func (Request) Content added in v1.0.2

func (r Request) Content() []byte

func (Request) ContentToString added in v1.1.0

func (r Request) ContentToString() string

func (*Request) Delete added in v1.0.3

func (r *Request) Delete(originUrl string, data map[string]interface{}) error

func (*Request) Download added in v1.0.7

func (r *Request) Download(filePath, originUrl string) error

func (*Request) DownloadWithRateLimit added in v1.1.2

func (r *Request) DownloadWithRateLimit(filePath, originUrl string, rate int64) error

func (*Request) Get added in v1.0.2

func (r *Request) Get(originUrl string, params map[string]string) error

func (*Request) ParseUrl added in v1.0.2

func (r *Request) ParseUrl(originUrl string) error

func (*Request) Post added in v1.0.2

func (r *Request) Post(originUrl string, data map[string]interface{}) error

func (*Request) PostForm added in v1.0.2

func (r *Request) PostForm(originUrl string, data map[string]string) error

func (*Request) Put added in v1.0.3

func (r *Request) Put(originUrl string, data map[string]interface{}) error

func (Request) Request added in v1.2.1

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

func (Request) Response added in v1.2.1

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

func (*Request) SetBasicAuth added in v1.0.3

func (r *Request) SetBasicAuth(username, password string)

func (*Request) SetBearerTokenAuth added in v1.0.3

func (r *Request) SetBearerTokenAuth(token string)

func (*Request) SetClient added in v1.2.10

func (r *Request) SetClient(client *http.Client)

func (*Request) SetHeader added in v1.0.3

func (r *Request) SetHeader(header map[string]string)

func (*Request) SetProxyEnv added in v1.2.12

func (r *Request) SetProxyEnv(proxy Proxy)

func (*Request) SetProxyFunc added in v1.2.12

func (r *Request) SetProxyFunc(f func(*http.Request) (*url.URL, error))

func (*Request) SetProxyUrl added in v1.2.12

func (r *Request) SetProxyUrl(proxy *url.URL)

func (*Request) SetSkipTLS added in v1.2.12

func (r *Request) SetSkipTLS()

func (*Request) SetTimeout added in v1.0.3

func (r *Request) SetTimeout(t time.Duration)

func (*Request) SetTransport added in v1.2.3

func (r *Request) SetTransport(rt http.RoundTripper)

func (Request) Status added in v1.0.2

func (r Request) Status() (int, string)

func (*Request) UnsetProxy added in v1.2.6

func (r *Request) UnsetProxy()

func (*Request) Upload added in v1.2.1

func (r *Request) Upload(originUrl string, data map[string]string, filePaths ...string) error

Jump to

Keyboard shortcuts

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