Documentation ¶
Index ¶
- Constants
- func CloseResponse(resp *http.Response)
- func Dir(dir string) http.FileSystem
- func ErrorCode(err error) int
- func ErrorMsg(err error) string
- func GetAdaptiveTimeoutClient() *http.Client
- func GetAdaptiveTransport(insecure bool) *http.Transport
- func GetAddrPort(urlStr string) (string, int, error)
- func GetClient(insecure bool, timeout time.Duration) *http.Client
- func GetDefaultClient() *http.Client
- func GetTimeoutClient(timeout time.Duration) *http.Client
- func GetTransport(insecure bool) *http.Transport
- func IsRedirectError(err error) bool
- func JSONRequest(client sClient, ctx context.Context, method THttpMethod, urlStr string, ...) (http.Header, jsonutils.JSONObject, error)
- func JSONRequestWithRetry(client sClient, ctx context.Context, method THttpMethod, urlStr string, ...) (http.Header, jsonutils.JSONObject, error)
- func JoinPath(ep string, paths ...string) string
- func MsgTmplToFmt(tmpl string) string
- func ParseJSONResponse(reqBody string, resp *http.Response, err error, debug bool) (http.Header, jsonutils.JSONObject, error)
- func ParseResponse(reqBody string, resp *http.Response, err error, debug bool) (http.Header, []byte, error)
- func Request(client sClient, ctx context.Context, method THttpMethod, urlStr string, ...) (*http.Response, error)
- func RequestWithRetry(client sClient, ctx context.Context, method THttpMethod, urlStr string, ...) (*http.Response, error)
- func SetClientProxyFunc(client *http.Client, proxyFunc TransportProxyFunc) bool
- type Error
- type FileSystem
- type JSONClientError
- type JSONClientErrorMsg
- type JsonBaseRequest
- func (req *JsonBaseRequest) GetHeader() http.Header
- func (req *JsonBaseRequest) GetHttpMethod() THttpMethod
- func (req *JsonBaseRequest) GetRequestBody() jsonutils.JSONObject
- func (req *JsonBaseRequest) GetUrl() string
- func (req *JsonBaseRequest) SetHeader(header http.Header)
- func (req *JsonBaseRequest) SetHttpMethod(method THttpMethod)
- type JsonClient
- type JsonRequest
- type JsonResponse
- type THttpMethod
- type TransportProxyFunc
Constants ¶
View Source
const ( USER_AGENT = "yunioncloud-go/201708" GET = THttpMethod("GET") HEAD = THttpMethod("HEAD") POST = THttpMethod("POST") PUT = THttpMethod("PUT") PATCH = THttpMethod("PATCH") DELETE = THttpMethod("DELETE") OPTION = THttpMethod("OPTION") IdleConnTimeout = 60 TLSHandshakeTimeout = 10 ResponseHeaderTimeout = 30 )
Variables ¶
This section is empty.
Functions ¶
func CloseResponse ¶
closeResponse close non nil response with any response Body. convenient wrapper to drain any remaining data on response body.
Subsequently this allows golang http RoundTripper to re-use the same connection for future requests.
func Dir ¶
func Dir(dir string) http.FileSystem
func GetAdaptiveTransport ¶
func GetDefaultClient ¶
func GetTransport ¶
func IsRedirectError ¶
func JSONRequest ¶
func JSONRequest(client sClient, ctx context.Context, method THttpMethod, urlStr string, header http.Header, body jsonutils.JSONObject, debug bool) (http.Header, jsonutils.JSONObject, error)
func JSONRequestWithRetry ¶
func JSONRequestWithRetry(client sClient, ctx context.Context, method THttpMethod, urlStr string, header http.Header, body jsonutils.JSONObject, debug bool) (http.Header, jsonutils.JSONObject, error)
func MsgTmplToFmt ¶
func ParseJSONResponse ¶
func ParseResponse ¶
func RequestWithRetry ¶
func SetClientProxyFunc ¶
func SetClientProxyFunc( client *http.Client, proxyFunc TransportProxyFunc, ) bool
Types ¶
type Error ¶
type Error struct { Id string `json:"id,omitempty"` Fields []interface{} `json:"fields,omitempty"` }
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
FileSystem custom file system handler
type JSONClientError ¶
type JSONClientError struct { Request struct { Method string `json:"method,omitempty"` Url string `json:"url,omitempty"` Body jsonutils.JSONObject `json:"body,omitempty"` Headers map[string]string `json:"headers,omitempty"` } `json:"request,omitempty"` Code int `json:"code,omitzero"` Class string `json:"class,omitempty"` Details string `json:"details,omitempty"` Data Error `json:"data,omitempty"` }
func NewJsonClientError ¶
func NewJsonClientError(code int, class string, msgFmt string, params ...interface{}) *JSONClientError
New a http Json client error code: http error code, >=400 class: error class msg: message params: message format parameters
func (*JSONClientError) Cause ¶
func (err *JSONClientError) Cause() error
func (*JSONClientError) Error ¶
func (e *JSONClientError) Error() string
func (*JSONClientError) ParseErrorFromJsonResponse ¶
func (ce *JSONClientError) ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error
type JSONClientErrorMsg ¶
type JSONClientErrorMsg struct {
Error *JSONClientError
}
type JsonBaseRequest ¶
type JsonBaseRequest struct {
// contains filtered or unexported fields
}
func NewJsonRequest ¶
func NewJsonRequest(method THttpMethod, url string, params interface{}) *JsonBaseRequest
func (*JsonBaseRequest) GetHeader ¶
func (req *JsonBaseRequest) GetHeader() http.Header
func (*JsonBaseRequest) GetHttpMethod ¶
func (req *JsonBaseRequest) GetHttpMethod() THttpMethod
func (*JsonBaseRequest) GetRequestBody ¶
func (req *JsonBaseRequest) GetRequestBody() jsonutils.JSONObject
func (*JsonBaseRequest) GetUrl ¶
func (req *JsonBaseRequest) GetUrl() string
func (*JsonBaseRequest) SetHeader ¶
func (req *JsonBaseRequest) SetHeader(header http.Header)
func (*JsonBaseRequest) SetHttpMethod ¶
func (req *JsonBaseRequest) SetHttpMethod(method THttpMethod)
type JsonClient ¶
type JsonClient struct {
// contains filtered or unexported fields
}
func NewJsonClient ¶
func NewJsonClient(client sClient) *JsonClient
func (*JsonClient) Send ¶
func (client *JsonClient) Send(ctx context.Context, req JsonRequest, response JsonResponse, debug bool) (http.Header, jsonutils.JSONObject, error)
type JsonRequest ¶
type JsonRequest interface { GetHttpMethod() THttpMethod GetRequestBody() jsonutils.JSONObject GetUrl() string SetHttpMethod(method THttpMethod) GetHeader() http.Header SetHeader(header http.Header) }
type JsonResponse ¶
type JsonResponse interface {
ParseErrorFromJsonResponse(statusCode int, body jsonutils.JSONObject) error
}
type THttpMethod ¶
type THttpMethod string
Click to show internal directories.
Click to hide internal directories.