rest

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager interface {
	// Get use bindSuccessTo and bindFailedTo to bind remote response to struct, while props to replace manager config on the fly
	Get(ctx context.Context, path string, params map[string]string, bindSuccessTo, bindFailedTo interface{}, opts ...Props) (httpCode int, err error)
	// Post use bindSuccessTo and bindFailedTo to bind remote response to struct, while props to replace manager config on the fly
	Post(ctx context.Context, path string, body interface{}, bindSuccessTo, bindFailedTo interface{}, opts ...Props) (httpCode int, err error)
	// Put use bindSuccessTo and bindFailedTo to bind remote response to struct, while props to replace manager config on the fly
	Put(ctx context.Context, path string, body interface{}, bindSuccessTo, bindFailedTo interface{}, opts ...Props) (httpCode int, err error)
	// Delete use bindSuccessTo and bindFailedTo to bind remote response to struct, while props to replace manager config on the fly
	Delete(ctx context.Context, path string, params map[string]string, bindSuccessTo, bindFailedTo interface{}, opts ...Props) (httpCode int, err error)
	// Head use bindSuccessTo and bindFailedTo to bind remote response to struct, while props to replace manager config on the fly
	Head(ctx context.Context, path string, bindSuccessTo, bindFailedTo interface{}, opts ...Props) (httpCode int, err error)
	// Patch use bindSuccessTo and bindFailedTo to bind remote response to struct, while props to replace manager config on the fly
	Patch(ctx context.Context, path string, body interface{}, bindSuccessTo, bindFailedTo interface{}, opts ...Props) (httpCode int, err error)

	CustomRequest(ctx context.Context, qp map[string]string, body interface{}, opts ...Props) *resty.Request
	GetClient() *resty.Client

	ManagerConfig
	// contains filtered or unexported methods
}

func New

func New(opts ...Option) Manager

type ManagerConfig

type ManagerConfig interface {
	SetName(name string) Manager
	BaseUrl() string
	ChangeBaseUrl(url string) Manager
	Transport() http.RoundTripper

	// SetDefaultHeaders will set headers that will exist on every request
	SetDefaultHeaders(values map[string]string) Manager
	// WithDefaultHeaders add additional headers on top of default headers
	WithDefaultHeaders(additionalHeaders map[string]string) Manager
	WithTransport(transport http.RoundTripper) Manager
	WithTelemetry(tm telemetry.Manager) Manager
	WithCircuitBreaker(
		maxRequest uint32, interval time.Duration,
		timeout time.Duration,
	) Manager
	// WithToken will set authentication token for every request (Authorization: Bearer)
	WithToken(token string) Manager
	DisableCircuitBreaker() Manager
}

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithBaseUrl

func WithBaseUrl(baseUrl string) Option

func WithDebugging

func WithDebugging(enabled bool) Option

func WithLogRequest

func WithLogRequest(v bool) Option

func WithLogResponse

func WithLogResponse(v bool) Option

func WithLogger

func WithLogger(l logger.Manager) Option

func WithMetrics

func WithMetrics(enabled bool, metric telemetry.MetricsManager) Option

func WithName

func WithName(name string) Option

func WithProxy

func WithProxy(addr string) Option

func WithTracing

func WithTracing(enabled bool) Option

func WithTransport

func WithTransport(t ...TransportOption) Option

type Props

type Props interface {
	// contains filtered or unexported methods
}

func AddHeader

func AddHeader(k, v string) Props

func AppendToHeaders

func AppendToHeaders(values map[string]string) Props

func ReplaceHeaders

func ReplaceHeaders(v map[string]string) Props

type Transport

type Transport interface {
	BuildRoundTripper() http.RoundTripper
}

func NewTransport

func NewTransport(opts ...TransportOption) Transport

type TransportOption

type TransportOption interface {
	// contains filtered or unexported methods
}

func TransportAppendReqIdHeaders

func TransportAppendReqIdHeaders(headers ...string) TransportOption

func TransportReqIdHeaders

func TransportReqIdHeaders(headers ...string) TransportOption

func TransportWithAttributes

func TransportWithAttributes(attributes ...attribute.KeyValue) TransportOption

TransportWithAttributes sets a list of attribute.KeyValue labels for all metrics associated with this round tripper

func TransportWithMeter

func TransportWithMeter(meter metric.Meter) TransportOption

TransportWithMeter sets the underlying metric.Meter that is used to create metric instruments By default the no-op meter is used.

func TransportWithName

func TransportWithName(name string) TransportOption

TransportWithName sets the prefix for the metrics emitted by this round tripper. by default, the "http.client" name is used.

func TransportWithParent

func TransportWithParent(parent http.RoundTripper) TransportOption

TransportWithParent sets the underlying http.RoundTripper which is wrapped by this round tripper. If the provided http.RoundTripper is nil, http.DefaultTransport will be used as the base http.RoundTripper

func TransportWithTelemetry

func TransportWithTelemetry(tm telemetry.Manager) TransportOption

TransportWithTelemetry trace the request with assigned telemetry manager

Jump to

Keyboard shortcuts

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