http

package
v1.8.24 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: Zlib Imports: 18 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 (
	FormType = reflect.TypeOf((*Form)(nil)).Elem()
)

Functions

func ConvertTo added in v1.1.32

func ConvertTo(data interface{}) url.Values

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
	TimeOut    time.Duration
	// contains filtered or unexported fields
}

func (*Http) Do

func (hp *Http) Do(method string, url string, body io.Reader, headerFunc HeaderFunc, reqOpts ...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, reqOpts ...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, reqOpts ...RequestOption) ([]byte, error)

func (*Http) DoString

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

func (*Http) DoWithHead

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

func (*Http) GetResponse added in v1.2.10

func (hp *Http) GetResponse() *Response

func (*Http) WithTimeout added in v1.2.10

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

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) 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