http

package
v0.0.0-...-512269d Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContentTypeJSON 表示JSON类型
	ContentTypeJSON = "application/json; charset=utf-8"
	// ContentTypeForm 表示Form类型
	ContentTypeForm = "application/x-www-form-urlencoded; charset=utf-8"
	// ContentTypeFormData 表示FormData类型
	ContentTypeFormData = "multipart/form-data; charset=utf-8"
	// ContentTypeText 表示Text类型
	ContentTypeText = "text/plain; charset=utf-8"
	// ContentTypeHTML 表示HTML类型
	ContentTypeHTML = "text/html; charset=utf-8"
	// ContentTypeXML 表示XML类型
	ContentTypeXML = "application/xml; charset=utf-8"

	// ContentTypeJSONP 表示JSONP类型
	ContentTypeJSONP = "application/javascript; charset=utf-8"
	// ContentTypeXHTML 表示XHTML类型
	ContentTypeXHTML = "application/xhtml+xml; charset=utf-8"

	// ContentTypePDF 表示PDF类型
	ContentTypePDF = "application/pdf; charset=utf-8"
	// ContentTypeZip 表示Zip类型
	ContentTypeZip = "application/zip; charset=utf-8"
	// ContentTypeGZIP 表示GZIP类型
	ContentTypeGZIP = "application/gzip; charset=utf-8"
	// ContentTypeBZIP2 表示BZIP2类型
	ContentTypeBZIP2 = "application/x-bzip2; charset=utf-8"
	// ContentTypeTAR 表示TAR类型
	ContentTypeTAR = "application/x-tar; charset=utf-8"
	// ContentTypeTARGZ 表示TARGZ类型
	ContentTypeTARGZ = "application/x-gzip; charset=utf-8"
	// ContentTypeTARBZ2 表示TARBZ2类型
	ContentTypeTARBZ2 = "application/x-bzip2; charset=utf-8"
	// ContentTypeTARZIP 表示TARZIP类型
	ContentTypeTARZIP = "application/x-compress; charset=utf-8"
	// ContentTypeTAR7Z 表示TAR7Z类型
	ContentTypeTAR7Z = "application/x-7z-compressed; charset=utf-8"
	// ContentTypeTARGZIP 表示TARGZIP类型
	ContentTypeTARGZIP = "application/x-gzip; charset=utf-8"

	// ContentTypeBMP 表示BMP类型
	ContentTypeBMP = "image/bmp; charset=utf-8"
	// ContentTypeICO 表示ICO类型
	ContentTypeICO = "image/vnd.microsoft.icon; charset=utf-8"
	// ContentTypeJPEG 表示JPEG类型
	ContentTypeJPEG = "image/jpeg; charset=utf-8"
	// ContentTypePNG 表示PNG类型
	ContentTypePNG = "image/png; charset=utf-8"
	// ContentTypeGIF 表示GIF类型
	ContentTypeGIF = "image/gif; charset=utf-8"
	// ContentTypeTIFF 表示TIFF类型
	ContentTypeTIFF = "image/tiff; charset=utf-8"
	// ContentTypeSVG 表示SVG类型
	ContentTypeSVG = "image/svg+xml; charset=utf-8"

	// ContentTypeMP3 表示MP3类型
	ContentTypeMP3 = "audio/mpeg; charset=utf-8"
	// ContentTypeWAV 表示WAV类型
	ContentTypeWAV = "audio/x-wav; charset=utf-8"
	// ContentTypeOGG 表示OGG类型
	ContentTypeOGG = "audio/ogg; charset=utf-8"
	// ContentTypeMP4 表示MP4类型
	ContentTypeMP4 = "video/mp4; charset=utf-8"
	// ContentTypeWebM 表示WebM类型
	ContentTypeWebM = "video/webm; charset=utf-8"
	// ContentTypeWMV 表示WMV类型
	ContentTypeWMV = "video/x-ms-wmv; charset=utf-8"
	// ContentTypeFLV 表示FLV类型
	ContentTypeFLV = "video/x-flv; charset=utf-8"
	// ContentTypeMKV 表示MKV类型
	ContentTypeMKV = "video/x-matroska; charset=utf-8"
	// ContentTypeAVI 表示AVI类型
	ContentTypeAVI = "video/x-msvideo; charset=utf-8"
	// ContentTypeMOV 表示MOV类型
	ContentTypeMOV = "video/quicktime; charset=utf-8"
	// ContentTypeWM 表示WM类型
	ContentTypeWM = "video/x-ms-wm; charset=utf-8"
	// ContentTypeASF 表示ASF类型
	ContentTypeASF = "video/x-ms-asf; charset=utf-8"
	// ContentType3GP 表示3GP类型
	ContentType3GP = "video/3gpp; charset=utf-8"
	// ContentType3G2 表示3G2类型
	ContentType3G2 = "video/3gpp2; charset=utf-8"
	// ContentTypeMP2 表示MP2类型
	ContentTypeMP2 = "video/mpeg; charset=utf-8"
	// ContentTypeMPEG 表示MPEG类型
	ContentTypeMPEG = "video/mpeg; charset=utf-8"
	// ContentTypeMPG 表示MPG类型
	ContentTypeMPG = "video/mpeg; charset=utf-8"

	// ContentTypeDOC 表示DOC类型
	ContentTypeDOC = "application/msword; charset=utf-8"
	// ContentTypeDOCX 表示DOCX类型
	ContentTypeDOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document; charset=utf-8"
	// ContentTypeXLS 表示XLS类型
	ContentTypeXLS = "application/vnd.ms-excel; charset=utf-8"
	// ContentTypeXLSX 表示XLSX类型
	ContentTypeXLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8"
	// ContentTypePPT 表示PPT类型
	ContentTypePPT = "application/vnd.ms-powerpoint; charset=utf-8"
	// ContentTypePPTX 表示PPTX类型
	ContentTypePPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation; charset=utf-8"
	// ContentTypeTXT 表示TXT类型
	ContentTypeTXT = "text/plain; charset=utf-8"
)

Variables

View Source
var Cli *http.Client = &http.Client{
	Timeout:   5 * time.Second,
	Transport: &http.Transport{MaxConnsPerHost: 100},
}

Functions

func GetUserAgent

func GetUserAgent(r *http.Request) string

func HttpGet

func HttpGet(url string) (body []byte, err error)

HttpGet 默认请求超时时间1秒

func HttpPost

func HttpPost(url string, data interface{}) (body []byte, err error)

HttpPost 默认请求超时时间1秒

func HttpPostForm

func HttpPostForm(url string, values url.Values) (body []byte, err error)

HttpPostForm 默认请求超时时间1秒

Types

type ReqBody

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

ReqBody 请求体

func (*ReqBody) AddParam

func (body *ReqBody) AddParam(key string, value interface{}) error

AddParam 为body添加参数, 仅form-data支持使用

func (*ReqBody) GetBodyInter

func (body *ReqBody) GetBodyInter() interface{}

GetBodyInter 获取bodyInter

func (*ReqBody) GetBodyReader

func (body *ReqBody) GetBodyReader() io.Reader

GetBodyReader 获取bodyReader

func (*ReqBody) GetContentType

func (body *ReqBody) GetContentType() string

GetContentType 获取contentType

func (*ReqBody) Set

func (body *ReqBody) Set(contentType string, bodyInter interface{}) error

Set 设置请求体

type ReqInput

type ReqInput struct {
	Header http.Header // 请求头
	Params url.Values  // 请求参数
	Body   *ReqBody    // 请求体
}

ReqInput 请求输入

func (*ReqInput) AddReqInputParam

func (rInput *ReqInput) AddReqInputParam(key string, value interface{})

type Request

type Request struct {
	Protocol   string // 协议
	DomainName string // 域名
	Port       string // 端口
	API        string // API接口
	Method     string // 请求方法 -> GET, POST, PUT, DELETE

}

Request 请求接口

type SimpleHttpClient

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

func NewSimpleHttpClient

func NewSimpleHttpClient() *SimpleHttpClient

func (*SimpleHttpClient) DELETE

func (client *SimpleHttpClient) DELETE(url string, header http.Header, data []byte) ([]byte, error)

func (*SimpleHttpClient) DELETEEx

func (client *SimpleHttpClient) DELETEEx(url string, header http.Header, data []byte) (int, []byte, error)

func (*SimpleHttpClient) DoWithTimeout

func (client *SimpleHttpClient) DoWithTimeout(timeout time.Duration, req *http.Request) (*http.Response, error)

func (*SimpleHttpClient) GET

func (client *SimpleHttpClient) GET(url string, header http.Header, data []byte) ([]byte, error)

func (*SimpleHttpClient) GETEx

func (client *SimpleHttpClient) GETEx(url string, header http.Header, data []byte) (int, []byte, error)

func (*SimpleHttpClient) GetClient

func (client *SimpleHttpClient) GetClient() *http.Client

func (*SimpleHttpClient) NewTransPort

func (client *SimpleHttpClient) NewTransPort() *http.Transport

func (*SimpleHttpClient) POST

func (client *SimpleHttpClient) POST(url string, header http.Header, data []byte) ([]byte, error)

func (*SimpleHttpClient) POSTEx

func (client *SimpleHttpClient) POSTEx(url string, header http.Header, data []byte) (int, []byte, error)

func (*SimpleHttpClient) PUT

func (client *SimpleHttpClient) PUT(url string, header http.Header, data []byte) ([]byte, error)

func (*SimpleHttpClient) PUTEx

func (client *SimpleHttpClient) PUTEx(url string, header http.Header, data []byte) (int, []byte, error)

func (*SimpleHttpClient) Request

func (client *SimpleHttpClient) Request(url, method string, header http.Header, data []byte) ([]byte, error)

func (*SimpleHttpClient) RequestEx

func (client *SimpleHttpClient) RequestEx(url, method string, header http.Header, data []byte) (int, []byte, error)

func (*SimpleHttpClient) SetHeader

func (client *SimpleHttpClient) SetHeader(key, value string)

func (*SimpleHttpClient) SetTimeOut

func (client *SimpleHttpClient) SetTimeOut(timeOut time.Duration)

Jump to

Keyboard shortcuts

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