Documentation ¶
Index ¶
- Constants
- func SetGlobalTransporterOverrider(fn TransporterOverrider)
- type Client
- type ContextKey
- type Instrumentation
- type Method
- type PreRequestFn
- type RESTRequest
- func (rr *RESTRequest) AddHeader(args ...string) *RESTRequest
- func (rr *RESTRequest) AddOption(fn ...SetRequestOptionFn) *RESTRequest
- func (rr *RESTRequest) AddQuery(args ...string) *RESTRequest
- func (rr *RESTRequest) Body(b interface{}) *RESTRequest
- func (rr *RESTRequest) Do(ctx context.Context, dst interface{}) (*http.Response, error)
- func (rr *RESTRequest) PreRequest(fn PreRequestFn) *RESTRequest
- type SetClientOptionsFn
- type SetRequestOptionFn
- func AddHeader(args ...string) SetRequestOptionFn
- func AddQuery(args ...string) SetRequestOptionFn
- func DisableCanonicalHeader() SetRequestOptionFn
- func PreRequest(fn PreRequestFn) SetRequestOptionFn
- func SetBody(body interface{}) SetRequestOptionFn
- func SetJsonBody(body interface{}) SetRequestOptionFn
- func SetUrlEncodedFormBody(body url.Values) SetRequestOptionFn
- func Timeout(ms int) SetRequestOptionFn
- type TransporterOverrider
Constants ¶
const ( MimeTypeJson = "application/json" MimeTypeUrlEncodedForm = "application/x-www-form-urlencoded" )
const (
ContextRequestId = iota + 1
)
const (
HeaderContentType = "Content-Type"
)
const (
InstrumentationOpenTelemetry = iota + 1
)
Variables ¶
This section is empty.
Functions ¶
func SetGlobalTransporterOverrider ¶ added in v0.7.0
func SetGlobalTransporterOverrider(fn TransporterOverrider)
SetGlobalTransporterOverrider set value to global overrideTransporter function. This function will override every transporter initiated afterward. Example use case is to wrap http.Client Transporter field with instrumentation such as OpenTelemetry otelhttp package (go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp)
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(baseUrl string, args ...SetClientOptionsFn) *Client
type ContextKey ¶
type ContextKey int8
type Instrumentation ¶ added in v0.6.0
type Instrumentation int8
type Method ¶
type Method = string
const ( MethodGet Method = "GET" MethodHead Method = "HEAD" MethodPost Method = "POST" MethodPut Method = "PUT" MethodPatch Method = "PATCH" // RFC 5789 MethodDelete Method = "DELETE" MethodConnect Method = "CONNECT" MethodOptions Method = "OPTIONS" MethodTrace Method = "TRACE" )
Common HTTP methods.
Unless otherwise noted, these are defined in RFC 7231 section 4.3.
type PreRequestFn ¶ added in v0.3.0
type RESTRequest ¶
type RESTRequest struct { Id string // contains filtered or unexported fields }
func NewRESTRequest ¶
func NewRESTRequest(c *Client, method Method, endpointPath string, args ...SetRequestOptionFn) *RESTRequest
NewRESTRequest creates a builder for REST API style request that use json as request and response body
func (*RESTRequest) AddHeader ¶
func (rr *RESTRequest) AddHeader(args ...string) *RESTRequest
func (*RESTRequest) AddOption ¶
func (rr *RESTRequest) AddOption(fn ...SetRequestOptionFn) *RESTRequest
func (*RESTRequest) AddQuery ¶
func (rr *RESTRequest) AddQuery(args ...string) *RESTRequest
func (*RESTRequest) Body ¶
func (rr *RESTRequest) Body(b interface{}) *RESTRequest
func (*RESTRequest) PreRequest ¶ added in v0.3.0
func (rr *RESTRequest) PreRequest(fn PreRequestFn) *RESTRequest
type SetClientOptionsFn ¶
type SetClientOptionsFn func(o *clientOptions)
func DisableHTTP2 ¶ added in v0.5.0
func DisableHTTP2() SetClientOptionsFn
DisableHTTP2 disable HTTP/2 alternate protocol
func LogDump ¶ added in v0.4.0
func LogDump(enable bool) SetClientOptionsFn
LogDump enable log HTTP request and response dump
func Namespace ¶
func Namespace(n string) SetClientOptionsFn
Namespace override default Client namespace value
type SetRequestOptionFn ¶
type SetRequestOptionFn func(o *requestOptions)
func AddHeader ¶
func AddHeader(args ...string) SetRequestOptionFn
func AddQuery ¶
func AddQuery(args ...string) SetRequestOptionFn
func DisableCanonicalHeader ¶ added in v0.5.0
func DisableCanonicalHeader() SetRequestOptionFn
func PreRequest ¶ added in v0.3.0
func PreRequest(fn PreRequestFn) SetRequestOptionFn
func SetBody ¶
func SetBody(body interface{}) SetRequestOptionFn
func SetJsonBody ¶
func SetJsonBody(body interface{}) SetRequestOptionFn
func SetUrlEncodedFormBody ¶ added in v0.2.0
func SetUrlEncodedFormBody(body url.Values) SetRequestOptionFn
func Timeout ¶
func Timeout(ms int) SetRequestOptionFn
type TransporterOverrider ¶ added in v0.7.0
type TransporterOverrider func(existing http.RoundTripper) http.RoundTripper
TransporterOverrider is a function to override how http client Transporter value. Could be used to wrap existing client Transporter (rt) for instrumentation or override Transporter value