http

package
v1.21.18 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Zlib Imports: 23 Imported by: 19

Documentation

Index

Constants

View Source
const (
	KContentType        = "Content-Type"
	KContentDisposition = "Content-Disposition"
	KContentLength      = "Content-Length"
)
View Source
const (
	MimeJSON          = "application/json"
	MimeHTML          = "text/html"
	MimeXML           = "application/xml"
	MimeXML2          = "text/xml"
	MimePlain         = "text/plain"
	MimeForm          = "application/x-www-form-urlencoded"
	MimeMultipartForm = "multipart/form-data"
	MimePROTOBUF      = "application/x-protobuf"
	MimeMSGPACK       = "application/x-msgpack"
	MimeMSGPACK2      = "application/msgpack"
	MimeYAML          = "application/x-yaml"
	MimeJSONUtf8      = "application/json;charset=UTF-8"
)
View Source
const URLTagName = "url"

Variables

View Source
var (
	HEAD   = Method("HEAD")
	GET    = Method("GET")
	POST   = Method("POST")
	PUT    = Method("PUT")
	DELETE = Method("DELETE")
)
View Source
var EnableLog bool = true
View Source
var (
	FormType = reflect.TypeOf((*Form)(nil)).Elem()
)

Functions

func ConvertTo added in v1.1.32

func ConvertTo(data interface{}) url.Values

func DefaultClient added in v1.10.3

func DefaultClient() *http.Client

DefaultClient returns a new http.Client with similar default values to http.Client, but with a non-shared Transport, idle connections disabled, and keepalives disabled.

func DefaultLog added in v1.20.81

func DefaultLog(in bool, method string, url string, seqNo string, no int64, res *Response)

func DefaultPooledClient added in v1.10.3

func DefaultPooledClient() *http.Client

DefaultPooledClient returns a new http.Client with similar default values to http.Client, but with a shared Transport. Do not use this function for transient clients as it can leak file descriptors over time. Only use this for clients that will be re-used for the same host(s).

func DefaultPooledTransport added in v1.10.3

func DefaultPooledTransport() *http.Transport

DefaultPooledTransport returns a new http.Transport with similar default values to http.DefaultTransport. Do not use this for transient transports as it can leak file descriptors over time. Only use this for transports that will be re-used for the same host(s).

func DefaultTransport added in v1.10.3

func DefaultTransport() *http.Transport

DefaultTransport returns a new http.Transport with similar default values to http.DefaultTransport, but with idle connections and keepalives disabled.

func Download added in v1.1.31

func Download(url string, filename string, perm os.FileMode) error

func URLWithParams added in v1.2.10

func URLWithParams(rawUrl string, params map[string]interface{}) (u *url.URL)

func URLWithPath added in v1.2.10

func URLWithPath(rawUrl string, path string, params map[string]interface{}) (u *url.URL)

func Upload added in v1.1.31

func Upload(url string, filename string, headerFunc HeaderFunc) ([]byte, error)

func UploadV2 added in v1.1.31

func UploadV2(url string, form Form, headerFunc HeaderFunc) ([]byte, error)

Types

type FileForm added in v1.1.31

type FileForm struct {
	Field string
	Value string
}

func (*FileForm) CreateForm added in v1.1.31

func (df *FileForm) CreateForm(w *multipart.Writer) error

type Form added in v1.1.31

type Form interface {
	CreateForm(w *multipart.Writer) error
}

type HeaderFunc added in v0.5.0

type HeaderFunc func(h *http.Header)

type Http

type Http struct {
	DisableLog bool
	SeqNo      string
	TimeOut    time.Duration
	// contains filtered or unexported fields
}

func (*Http) Do

func (hp *Http) Do(method string, url string, body io.Reader, headerFunc HeaderFunc, opts ...RequestOption) ([]byte, error)

func (*Http) DoBytes

func (hp *Http) DoBytes(method string, url string, buf []byte, reqOpts ...RequestOption) ([]byte, error)

func (*Http) DoForm added in v0.2.6

func (hp *Http) DoForm(url string, reqOpts ...RequestOption) ([]byte, error)

DoForm url http://api.xxx.com/ssddd?key=ddd&ddd=sfsf

func (*Http) DoFormWith added in v0.2.6

func (hp *Http) DoFormWith(rawUrl, query string, reqOpts ...RequestOption) ([]byte, error)

DoFormWith query ssddd=sdsfs&sfssfs=sfsssfs&sfsfsfs&

func (*Http) DoFormWithValues added in v0.2.6

func (hp *Http) DoFormWithValues(url string, values url.Values, opts ...RequestOption) ([]byte, error)

func (*Http) DoMultiForm added in v0.2.6

func (hp *Http) DoMultiForm(url string, reqOpts ...RequestOption) ([]byte, error)

func (*Http) DoMultiFormWith added in v0.2.6

func (hp *Http) DoMultiFormWith(rawUrl, query string, reqOpts ...RequestOption) ([]byte, error)

func (*Http) DoMultiFormWithValues added in v0.2.6

func (hp *Http) DoMultiFormWithValues(url string, form url.Values, opts ...RequestOption) ([]byte, error)

func (*Http) DoString

func (hp *Http) DoString(method string, url string, buf []byte, reqOpts ...RequestOption) (string, error)

func (*Http) DoV2 added in v1.20.81

func (hp *Http) DoV2(method string, url string, body io.Reader, headerFunc HeaderFunc, logger LogFunc, opts ...RequestOption) ([]byte, error)

func (*Http) DoWithHead

func (hp *Http) DoWithHead(method string, url string, buf []byte, headerFunc HeaderFunc, opts ...RequestOption) ([]byte, error)

func (*Http) GetResponse added in v1.2.10

func (hp *Http) GetResponse() *Response

func (*Http) LogEnabled added in v1.8.50

func (hp *Http) LogEnabled() bool

func (*Http) SetNewHttpClient added in v1.10.3

func (hp *Http) SetNewHttpClient(fn NewHttpClientFunc)

func (*Http) WithTimeout added in v1.2.10

func (hp *Http) WithTimeout(duration time.Duration) *Http

type LogFunc added in v1.20.81

type LogFunc func(in bool, method string, url string, seqNo string, no int64, res *Response)

type NewHttpClientFunc added in v1.10.3

type NewHttpClientFunc func(h *Http, timeout time.Duration) *http.Client

type ReadForm added in v1.1.31

type ReadForm struct {
	Field string
	Value string
	R     io.Reader
}

func (*ReadForm) CreateForm added in v1.1.31

func (df *ReadForm) CreateForm(w *multipart.Writer) error

type RequestOption added in v1.2.10

type RequestOption func(req *http.Request) (*http.Request, error)

func Accept added in v1.2.10

func Accept(ct string) RequestOption

func Body added in v1.2.10

func Body(r io.Reader) RequestOption

func ContentLength added in v1.2.10

func ContentLength(l int64) RequestOption

func ContentType added in v1.2.10

func ContentType(ct string) RequestOption

func Context added in v1.2.10

func Context(ctx context.Context) RequestOption

func FormBody added in v1.2.10

func FormBody(params map[string]interface{}) RequestOption
func Header(headers map[string]string) RequestOption

func JsonBody added in v1.2.10

func JsonBody(body interface{}) RequestOption

func Method added in v1.2.10

func Method(m string) RequestOption

func Params added in v1.2.10

func Params(params map[string]interface{}) RequestOption

func Path added in v1.2.10

func Path(path string) RequestOption

func StringParams added in v1.2.10

func StringParams(params map[string]string) RequestOption

func Trace added in v1.2.10

func Trace(tracer *httptrace.ClientTrace) RequestOption

func URL added in v1.2.10

func URL(u *url.URL) RequestOption

func URLString added in v1.2.10

func URLString(rawUrl string) RequestOption

type Response added in v1.2.10

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

Response 请求回应

func (*Response) Error added in v1.20.81

func (res *Response) Error() error

func (*Response) FileName added in v1.2.10

func (res *Response) FileName() string

func (*Response) GetBody added in v1.2.10

func (res *Response) GetBody() []byte

func (*Response) GetContentDisposition added in v1.2.10

func (res *Response) GetContentDisposition() string

func (*Response) GetContentLength added in v1.2.10

func (res *Response) GetContentLength() int64

func (*Response) GetContentType added in v1.2.10

func (res *Response) GetContentType() string

func (*Response) IsFile added in v1.2.10

func (res *Response) IsFile() bool

func (*Response) Reset added in v1.2.10

func (res *Response) Reset()

type Url added in v1.1.36

type Url struct {
	url.Values
}

func NewUrl added in v1.1.36

func NewUrl() Url

func WithParams added in v1.2.10

func WithParams(data interface{}) Url

func (Url) Generate added in v1.1.36

func (u Url) Generate(url, suffix string) string

func (Url) Parse added in v1.1.36

func (u Url) Parse(data interface{})

Jump to

Keyboard shortcuts

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