Documentation
¶
Index ¶
- Constants
- func DeleteAndParse[T any](client *http.Client, url string, options ...HttpOptions) (*T, error)
- func GetAndParse[T any](client *http.Client, url string, options ...HttpOptions) (*T, error)
- func GetAndParseStream[T any](client *http.Client, url string, options ...HttpOptions) (*stream.Stream[T], error)
- func PatchAndParse[T any](client *http.Client, url string, options ...HttpOptions) (*T, error)
- func PostAndParse[T any](client *http.Client, url string, options ...HttpOptions) (*T, error)
- func PostAndParseStream[T any](client *http.Client, url string, options ...HttpOptions) (*stream.Stream[T], error)
- func PutAndParse[T any](client *http.Client, url string, options ...HttpOptions) (*T, error)
- func PutAndParseStream[T any](client *http.Client, url string, options ...HttpOptions) (*stream.Stream[T], error)
- func Request(client *http.Client, url string, method string, options ...HttpOptions) (*http.Response, error)
- func RequestAndParse[T any](client *http.Client, url string, method string, options ...HttpOptions) (*T, error)
- func RequestAndParseStream[T any](client *http.Client, url string, method string, options ...HttpOptions) (*stream.Stream[T], error)
- type HttpOptions
- func HttpHeader(header map[string]string) HttpOptions
- func HttpParams(params map[string]string) HttpOptions
- func HttpPayload(payload map[string]string) HttpOptions
- func HttpPayloadJson(payload interface{}) HttpOptions
- func HttpPayloadMultipart(payload map[string]string, files map[string]HttpPayloadMultipartFile) HttpOptions
- func HttpPayloadReader(reader io.ReadCloser) HttpOptions
- func HttpPayloadText(payload string) HttpOptions
- func HttpRaiseErrorWhenStreamDataNotMatch(raise bool) HttpOptions
- func HttpReadTimeout(timeout int64) HttpOptions
- func HttpUsingLengthPrefixed(using bool) HttpOptions
- func HttpWithDirectReferer() HttpOptions
- func HttpWithRetCode(retCode *int) HttpOptions
- func HttpWriteTimeout(timeout int64) HttpOptions
- type HttpPayloadMultipartFile
Constants ¶
View Source
const ( HttpOptionTypeWriteTimeout = "write_timeout" HttpOptionTypeReadTimeout = "read_timeout" HttpOptionTypeHeader = "header" HttpOptionTypeParams = "params" HttpOptionTypePayload = "payload" HttpOptionTypePayloadText = "payloadText" HttpOptionTypePayloadJson = "payloadJson" HttpOptionTypePayloadMultipart = "payloadMultipart" HttpOptionTypeRaiseErrorWhenStreamDataNotMatch = "raiseErrorWhenStreamDataNotMatch" HttpOptionTypeDirectReferer = "directReferer" HttpOptionTypeRetCode = "retCode" HttpOptionTypeUsingLengthPrefixed = "usingLengthPrefixed" )
Variables ¶
This section is empty.
Functions ¶
func DeleteAndParse ¶
func GetAndParse ¶
func GetAndParseStream ¶
func PatchAndParse ¶
func PostAndParse ¶
func PostAndParseStream ¶
func PutAndParse ¶
func PutAndParseStream ¶
func RequestAndParse ¶
Types ¶
type HttpOptions ¶
type HttpOptions struct {
Type string
Value interface{}
}
func HttpHeader ¶
func HttpHeader(header map[string]string) HttpOptions
func HttpParams ¶
func HttpParams(params map[string]string) HttpOptions
which is used for params with in url
func HttpPayload ¶
func HttpPayload(payload map[string]string) HttpOptions
which is used for POST method only
func HttpPayloadJson ¶
func HttpPayloadJson(payload interface{}) HttpOptions
which is used for POST method only
func HttpPayloadMultipart ¶
func HttpPayloadMultipart(payload map[string]string, files map[string]HttpPayloadMultipartFile) HttpOptions
which is used for POST method only payload follows the form data format, and files is a map from filename to file
func HttpPayloadReader ¶
func HttpPayloadReader(reader io.ReadCloser) HttpOptions
which is used for POST method only
func HttpPayloadText ¶
func HttpPayloadText(payload string) HttpOptions
which is used for POST method only
func HttpRaiseErrorWhenStreamDataNotMatch ¶
func HttpRaiseErrorWhenStreamDataNotMatch(raise bool) HttpOptions
func HttpUsingLengthPrefixed ¶
func HttpUsingLengthPrefixed(using bool) HttpOptions
For standard SSE protocol, response are split by \n\n Which leads a bad performance when decoding, we need a larger chunk to store temporary data This option is used to enable length-prefixed mode, which is faster but less memory-friendly We uses following format:
| Field | Size | Description | |---------------|----------|---------------------------------| | Magic Number | 1 byte | Magic number identifier | | Reserved | 1 byte | Reserved field | | Header Length | 2 bytes | Header length (usually 0xa) | | Data Length | 4 bytes | Length of the data | | Reserved | 6 bytes | Reserved fields | | Data | Variable | Actual data content | | Reserved Fields | Header | Data | |-----------------|----------|----------| | 4 bytes total | Variable | Variable |
with the above format, we can achieve a better performance, avoid unexpected memory growth
func HttpWithDirectReferer ¶
func HttpWithDirectReferer() HttpOptions
func HttpWithRetCode ¶
func HttpWithRetCode(retCode *int) HttpOptions
Click to show internal directories.
Click to hide internal directories.