httpclient

package
v0.0.0-...-08b9edc Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2021 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNS              = errorx.NewNamespace("http_client")
	ErrInvalidEndpoint = ErrNS.NewType("invalid_endpoint")
	ErrServerError     = ErrNS.NewType("server_error")
)

Functions

This section is empty.

Types

type APIClientConfig

type APIClientConfig struct {
	// Endpoint is required in format `http(s)://host:port`.
	// If TLS is specified, `http://` will be updated to `https://`.
	Endpoint string
	Context  context.Context
	TLS      *tls.Config
}

func (APIClientConfig) IntoConfig

func (dc APIClientConfig) IntoConfig(kindTag string) (Config, error)

type Client

type Client struct {
	nocopy.NoCopy
	// contains filtered or unexported fields
}

Client is a lightweight wrapper over resty.Client, providing default error handling and timeout settings. WARN: This structure is not thread-safe.

func New

func New(config Config) *Client

func (*Client) LifecycleR

func (c *Client) LifecycleR() *Request

LifecycleR builds a new Request with the default lifecycle context and the default timeout. This function is intentionally not named as `R()` to avoid being confused with `resty.Client.R()`.

func (*Client) SetHeader

func (c *Client) SetHeader(header, value string) *Client

type Config

type Config struct {
	BaseURL string
	Context context.Context
	TLS     *tls.Config
	KindTag string // Used to mark what kind of HttpClient it is in error messages and logs.
}

type Request

type Request struct {
	nocopy.NoCopy
	// contains filtered or unexported fields
}

Request is a lightweight wrapper over resty.Request. Different to resty.Request, it enforces a timeout. WARN: This structure is not thread-safe.

func (*Request) Delete

func (r *Request) Delete(url string) (context.CancelFunc, *resty.Response, error)

WARN: The returned cancelFunc must be called to avoid context leak.

func (*Request) EnableTrace

func (r *Request) EnableTrace() *Request

func (*Request) Execute

func (r *Request) Execute(method, url string) (context.CancelFunc, *resty.Response, error)

WARN: The returned cancelFunc must be called to avoid context leak.

func (*Request) ExpectContentType

func (r *Request) ExpectContentType(contentType string) *Request

func (*Request) ForceContentType

func (r *Request) ForceContentType(contentType string) *Request

func (*Request) Get

func (r *Request) Get(url string) (context.CancelFunc, *resty.Response, error)

WARN: The returned cancelFunc must be called to avoid context leak.

func (*Request) Post

func (r *Request) Post(url string) (context.CancelFunc, *resty.Response, error)

WARN: The returned cancelFunc must be called to avoid context leak.

func (*Request) Put

func (r *Request) Put(url string) (context.CancelFunc, *resty.Response, error)

WARN: The returned cancelFunc must be called to avoid context leak.

func (*Request) SetAuthScheme

func (r *Request) SetAuthScheme(scheme string) *Request

func (*Request) SetAuthToken

func (r *Request) SetAuthToken(token string) *Request

func (*Request) SetBasicAuth

func (r *Request) SetBasicAuth(username, password string) *Request

func (*Request) SetBody

func (r *Request) SetBody(body interface{}) *Request

func (*Request) SetContentLength

func (r *Request) SetContentLength(l bool) *Request

func (*Request) SetContext

func (r *Request) SetContext(ctx context.Context) *Request

func (*Request) SetCookie

func (r *Request) SetCookie(hc *http.Cookie) *Request

func (*Request) SetCookies

func (r *Request) SetCookies(rs []*http.Cookie) *Request

func (*Request) SetDoNotParseResponse

func (r *Request) SetDoNotParseResponse(parse bool) *Request

func (*Request) SetError

func (r *Request) SetError(err interface{}) *Request

func (*Request) SetFile

func (r *Request) SetFile(param, filePath string) *Request

func (*Request) SetFileReader

func (r *Request) SetFileReader(param, fileName string, reader io.Reader) *Request

func (*Request) SetFiles

func (r *Request) SetFiles(files map[string]string) *Request

func (*Request) SetFormData

func (r *Request) SetFormData(data map[string]string) *Request

func (*Request) SetFormDataFromValues

func (r *Request) SetFormDataFromValues(data url.Values) *Request

func (*Request) SetHeader

func (r *Request) SetHeader(header, value string) *Request

func (*Request) SetHeaderVerbatim

func (r *Request) SetHeaderVerbatim(header, value string) *Request

func (*Request) SetHeaders

func (r *Request) SetHeaders(headers map[string]string) *Request

func (*Request) SetJSONEscapeHTML

func (r *Request) SetJSONEscapeHTML(b bool) *Request

func (*Request) SetJSONResult

func (r *Request) SetJSONResult(res interface{}) *Request

SetJSONResult expects a JSON response from the remote endpoint and specify how response is deserialized.

func (*Request) SetMultipartField

func (r *Request) SetMultipartField(param, fileName, contentType string, reader io.Reader) *Request

func (*Request) SetMultipartFields

func (r *Request) SetMultipartFields(fields ...*resty.MultipartField) *Request

func (*Request) SetMultipartFormData

func (r *Request) SetMultipartFormData(data map[string]string) *Request

func (*Request) SetOutput

func (r *Request) SetOutput(file string) *Request

func (*Request) SetPathParam

func (r *Request) SetPathParam(param, value string) *Request

func (*Request) SetPathParams

func (r *Request) SetPathParams(params map[string]string) *Request

func (*Request) SetQueryParam

func (r *Request) SetQueryParam(param, value string) *Request

func (*Request) SetQueryParams

func (r *Request) SetQueryParams(params map[string]string) *Request

func (*Request) SetQueryParamsFromValues

func (r *Request) SetQueryParamsFromValues(params url.Values) *Request

func (*Request) SetQueryString

func (r *Request) SetQueryString(query string) *Request

func (*Request) SetSRV

func (r *Request) SetSRV(srv *resty.SRVRecord) *Request

func (*Request) SetTimeout

func (r *Request) SetTimeout(timeout time.Duration) *Request

func (*Request) TraceInfo

func (r *Request) TraceInfo() resty.TraceInfo

Jump to

Keyboard shortcuts

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