Documentation ¶
Index ¶
- Variables
- func CodecForRequest(r *http.Request, name ...string) (encoding.Codec, bool)
- func CodecForResponse(r *http.Response, name ...string) (encoding.Codec, bool)
- func ContentSubtype(contentType string) string
- func ForceHttps(endpoint string) string
- func FullPath(endpoint, path string) string
- func GetCodecByContentType(contentType string) encoding.Codec
- func IsHTTPNot2xxError(err error) bool
- func Not2xxCode(code int) bool
- func ProxyURL(address string) func(*http.Request) (*url.URL, error)
- func RegisterCodecByContentType(contentType string, codec encoding.Codec)
- func RegisterCodecNameByContentType(contentType string, name string)
- type CallOption
- type CallOptions
- type Client
- func (c *Client) BindResponseBody(response *http.Response, reply any) error
- func (c *Client) Do(req *http.Request, opts ...CallOption) (*http.Response, error)
- func (c *Client) Endpoint() string
- func (c *Client) Invoke(ctx context.Context, method, path string, args any, reply any, ...) (*http.Response, error)
- func (c *Client) SetEndpoint(endpoint string)
- type ClientOption
- func WithContentType(contentType string) ClientOption
- func WithDebug(f func() DebugInterface) ClientOption
- func WithEndpoint(endpoint string) ClientOption
- func WithNot2xxError(f func() Not2xxError) ClientOption
- func WithProxy(f func(*http.Request) (*url.URL, error)) ClientOption
- func WithTLSConfig(cfg *tls.Config) ClientOption
- func WithTimeout(timeout time.Duration) ClientOption
- func WithTransport(transport http.RoundTripper) ClientOption
- func WithUserAgent(userAgent string) ClientOption
- type Debug
- type DebugInterface
- type HTTPNot2xxError
- type Not2xxError
- type TraceInfo
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultDebug = func() DebugInterface { return &Debug{ Writer: os.Stderr, Trace: true, TraceCallback: func(w io.Writer, info TraceInfo) { _, _ = w.Write(info.Table()) }, } }
Functions ¶
func CodecForRequest ¶ added in v1.0.1
CodecForRequest get encoding.Codec via http.Request
func CodecForResponse ¶ added in v1.0.1
CodecForResponse get encoding.Codec via http.Response
func ContentSubtype ¶
func ForceHttps ¶
func GetCodecByContentType ¶ added in v1.0.5
func IsHTTPNot2xxError ¶ added in v1.0.6
func Not2xxCode ¶
func RegisterCodecByContentType ¶ added in v1.0.5
func RegisterCodecNameByContentType ¶ added in v1.1.0
Types ¶
type CallOption ¶
type CallOptions ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an HTTP client.
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
func (*Client) BindResponseBody ¶ added in v1.0.1
func (*Client) Do ¶ added in v1.0.1
Do send an HTTP request and decodes the body of response into target.
func (*Client) Invoke ¶
func (c *Client) Invoke(ctx context.Context, method, path string, args any, reply any, opts ...CallOption) (*http.Response, error)
Invoke makes a rpc call procedure for remote service.
func (*Client) SetEndpoint ¶
type ClientOption ¶
type ClientOption func(*clientOptions)
ClientOption is HTTP client option.
func WithContentType ¶
func WithContentType(contentType string) ClientOption
WithContentType with client request content type.
func WithNot2xxError ¶
func WithNot2xxError(f func() Not2xxError) ClientOption
WithNot2xxError handle response status code < 200 and code > 299
func WithTLSConfig ¶
func WithTLSConfig(cfg *tls.Config) ClientOption
WithTLSConfig with tls config.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout with client request timeout.
func WithTransport ¶ added in v1.0.1
func WithTransport(transport http.RoundTripper) ClientOption
WithTransport with http.RoundTrippe.
func WithUserAgent ¶
func WithUserAgent(userAgent string) ClientOption
WithUserAgent with client user agent.
type Debug ¶ added in v1.0.1
type Debug struct { Writer io.Writer Trace bool TraceCallback func(w io.Writer, info TraceInfo) // contains filtered or unexported fields }
func (*Debug) Before ¶ added in v1.0.1
func (d *Debug) Before() *httptrace.ClientTrace
type DebugInterface ¶ added in v1.0.1
type HTTPNot2xxError ¶ added in v1.0.6
type HTTPNot2xxError struct { URL *url.URL Method string StatusCode int Err Not2xxError }
func ConvertToHTTPNot2xxError ¶ added in v1.0.6
func ConvertToHTTPNot2xxError(err error) (*HTTPNot2xxError, bool)
func (HTTPNot2xxError) Error ¶ added in v1.0.6
func (h HTTPNot2xxError) Error() string
type Not2xxError ¶
type Not2xxError interface {
String() string
}
type TraceInfo ¶ added in v1.0.1
type TraceInfo struct { DNSDuration time.Duration `json:"DNSDuration,omitempty" yaml:"DNSDuration" xml:"DNSDuration"` ConnectDuration time.Duration `json:"connectDuration,omitempty" yaml:"connectDuration" xml:"connectDuration"` TLSHandshakeDuration time.Duration `json:"TLSHandshakeDuration,omitempty" yaml:"TLSHandshakeDuration" xml:"TLSHandshakeDuration"` RequestDuration time.Duration `json:"requestDuration,omitempty" yaml:"requestDuration" xml:"requestDuration"` WaitResponseDuration time.Duration `json:"waitResponseDuration,omitempty" yaml:"waitResponseDuration" xml:"waitResponseDuration"` ResponseDuration time.Duration `json:"responseDuration,omitempty" yaml:"responseDuration" xml:"responseDuration"` TotalDuration time.Duration `json:"totalDuration,omitempty" yaml:"totalDuration" xml:"totalDuration"` // contains filtered or unexported fields }
Click to show internal directories.
Click to hide internal directories.