httputils

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 25 Imported by: 31

Documentation

Index

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

	ConnectionTimeoutSeconds     = 120
	IdleConnTimeoutSeconds       = 60
	TLSHandshakeTimeoutSeconds   = 10
	ResponseHeaderTimeoutSeconds = 30
)

Variables

This section is empty.

Functions

func CloseResponse

func CloseResponse(resp *http.Response)

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 ErrorCode

func ErrorCode(err error) int

func ErrorMsg

func ErrorMsg(err error) string

func GetAdaptiveTimeoutClient

func GetAdaptiveTimeoutClient() *http.Client

func GetAdaptiveTransport

func GetAdaptiveTransport(insecure bool) *http.Transport

func GetAddrPort

func GetAddrPort(urlStr string) (string, int, error)

func GetClient

func GetClient(insecure bool, timeout time.Duration) *http.Client

func GetDefaultClient

func GetDefaultClient() *http.Client

func GetTimeoutClient

func GetTimeoutClient(timeout time.Duration) *http.Client

func GetTransport

func GetTransport(insecure bool) *http.Transport

func IsRedirectError

func IsRedirectError(err error) bool

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 JoinPath

func JoinPath(ep string, paths ...string) string

func MsgTmplToFmt

func MsgTmplToFmt(tmpl string) string

func ParseJSONResponse

func ParseJSONResponse(reqBody string, resp *http.Response, err error, debug bool) (http.Header, jsonutils.JSONObject, error)

func ParseResponse

func ParseResponse(reqBody string, resp *http.Response, err error, debug bool) (http.Header, []byte, error)

func Request

func Request(client sClient, ctx context.Context, method THttpMethod, urlStr string, header http.Header, body io.Reader, debug bool) (*http.Response, error)

func RequestWithRetry

func RequestWithRetry(client sClient, ctx context.Context, method THttpMethod, urlStr string, header http.Header, body io.Reader, debug bool) (*http.Response, error)

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

func (FileSystem) Open

func (fs FileSystem) Open(path string) (http.File, error)

Open opens file

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, status string, 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, status string, body jsonutils.JSONObject) error
}

type THttpMethod

type THttpMethod string

type TransportProxyFunc

type TransportProxyFunc func(*http.Request) (*url.URL, error)

Jump to

Keyboard shortcuts

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