Documentation ¶
Index ¶
- func CurlLikeDumpRequest(req *http.Request)
- func CurlLikeDumpResponse(resp *http.Response)
- func Delete(ctx context.Context, url string, resp interface{}, opts ...ReqOptionFunc) error
- func ForwardHeaders(headers http.Header) map[string]string
- func Get(ctx context.Context, url string, resp interface{}, opts ...ReqOptionFunc) error
- func GetErrorCode(err error) (int, bool)
- func GetErrorMessage(err error) string
- func HttpRequest(ctx context.Context, method, addr string, req, resp interface{}, ...) error
- func IsErrorCode(err error, code int) bool
- func NewRequestError(statusCode int, message string) error
- func Patch(ctx context.Context, url string, req, resp interface{}, opts ...ReqOptionFunc) error
- func Post(ctx context.Context, url string, req, resp interface{}, opts ...ReqOptionFunc) error
- func Put(ctx context.Context, url string, req, resp interface{}, opts ...ReqOptionFunc) error
- type MarshalFunc
- type PrintfFunc
- type ReqOptionFunc
- func StoreStatusCode(statusCode *int) ReqOptionFunc
- func WithClient(client *http.Client) ReqOptionFunc
- func WithDumpRequest(dumpRequest, dumpResponse bool) ReqOptionFunc
- func WithHeader(header map[string]string) ReqOptionFunc
- func WithLogTimeCost(printfer ...PrintfFunc) ReqOptionFunc
- func WithMarshal(marshaler MarshalFunc) ReqOptionFunc
- func WithStatusCodeJudge(codeJudger StatusCodeJudgeFunc) ReqOptionFunc
- func WithTimeout(timeout time.Duration) ReqOptionFunc
- func WithTraceHeaders(headers http.Header) ReqOptionFunc
- func WithUnmarshal(unmarshaler UnmarshalFunc) ReqOptionFunc
- type RequestError
- type StatusCodeJudgeFunc
- type UnmarshalFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurlLikeDumpRequest ¶
func CurlLikeDumpResponse ¶
func Delete ¶
func Delete(ctx context.Context, url string, resp interface{}, opts ...ReqOptionFunc) error
Delete http request
func ForwardHeaders ¶
ForwardHeaders forward trace headers refer: https://github.com/istio/istio/blob/31692397b17c1ad89c4227fd5b1696cba4027978/samples/bookinfo/src/productpage/productpage.py#L162
func Get ¶
func Get(ctx context.Context, url string, resp interface{}, opts ...ReqOptionFunc) error
Get http request
func GetErrorCode ¶
GetErrorCode get http request's status code
func GetErrorMessage ¶
GetErrorMessage get http request's error message
func HttpRequest ¶
func HttpRequest(ctx context.Context, method, addr string, req, resp interface{}, opts ...ReqOptionFunc) error
http request req, resp are point type
func IsErrorCode ¶
IsErrorCode juede http request's stauts code
func NewRequestError ¶
NewRequestError new httputil error
func Patch ¶
func Patch(ctx context.Context, url string, req, resp interface{}, opts ...ReqOptionFunc) error
Patch http request
Types ¶
type MarshalFunc ¶
MarshalFunc marshal request function
type PrintfFunc ¶
type PrintfFunc func(format string, v ...interface{})
PrintfFunc for print request log
type ReqOptionFunc ¶
type ReqOptionFunc func(opt *reqOptions) error
ReqOptionFunc request option function
func StoreStatusCode ¶
func StoreStatusCode(statusCode *int) ReqOptionFunc
StoreStatusCode default: not store, just judge
func WithClient ¶
func WithClient(client *http.Client) ReqOptionFunc
WithClient default: &http.Client{}
func WithDumpRequest ¶
func WithDumpRequest(dumpRequest, dumpResponse bool) ReqOptionFunc
WithDumpRequest default: false, false
func WithHeader ¶
func WithHeader(header map[string]string) ReqOptionFunc
WithHeader default: "Accept": "application/json", "Content-Type": "application/json;charset=UTF-8"
func WithLogTimeCost ¶
func WithLogTimeCost(printfer ...PrintfFunc) ReqOptionFunc
WithLogTimeCost default: false, logger.Printf
func WithMarshal ¶
func WithMarshal(marshaler MarshalFunc) ReqOptionFunc
WithMarshal default: json.Marshal
func WithStatusCodeJudge ¶
func WithStatusCodeJudge(codeJudger StatusCodeJudgeFunc) ReqOptionFunc
WithStatusCodeJudge default: defaultCodeJudger
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ReqOptionFunc
WithTimeout default: 30 * time.Second
func WithTraceHeaders ¶
func WithTraceHeaders(headers http.Header) ReqOptionFunc
WithTraceHeaders append trace headers NOTE: 1. This should only be used in the demo project. 2. If the WithHeader method is used, it should be used after it.
func WithUnmarshal ¶
func WithUnmarshal(unmarshaler UnmarshalFunc) ReqOptionFunc
WithUnmarshal default: json.Unmarshal
type RequestError ¶
RequestError httputil request error
func (*RequestError) Error ¶
func (e *RequestError) Error() string
type StatusCodeJudgeFunc ¶
StatusCodeJudgeFunc for judge status code (right status code return true)
type UnmarshalFunc ¶
UnmarshalFunc unmarshal response function