Documentation
¶
Index ¶
- func IsClientError(response *resty.Response) bool
- func IsNotFound(response *resty.Response) bool
- func IsServerError(response *resty.Response) bool
- func IsUnauthorized(response *resty.Response) bool
- type Client
- func (c *Client) AddMiddleware(middleware Middleware)
- func (c *Client) GetMiddlewares() []Middleware
- func (c *Client) GetRestClient() *resty.Client
- func (c *Client) GetRestConfig() *Config
- func (c *Client) HandleResponse(response *resty.Response) error
- func (c *Client) MakeRequest(ctx context.Context, method string, url string, body string, ...) (*resty.Response, error)
- func (c *Client) MakeRequestWithTrace(ctx context.Context, method string, url string, body string, ...) (*resty.Response, error)
- func (c *Client) SetMiddlewares(middlewares ...Middleware)
- type ClientOption
- type Config
- type DatabaseLoggingMiddleware
- type ExecutionError
- type LoggingMiddleware
- type Middleware
- type NoOpMiddleware
- type OTelLoggingMiddleware
- type OTelMetricsMiddleware
- func (m *OTelMetricsMiddleware) AfterRequest(ctx context.Context, info RequestInfo)
- func (m *OTelMetricsMiddleware) BeforeRequest(ctx context.Context, method string, url string, body string, ...) context.Context
- func (m *OTelMetricsMiddleware) RecordRetry(ctx context.Context, method string, attempt int)
- type OTelTracingMiddleware
- type RequestInfo
- type ResourceNotFoundError
- type ResponseError
- type ServerError
- type UnauthorizedError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsClientError ¶
func IsNotFound ¶
func IsServerError ¶
func IsUnauthorized ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(options ...ClientOption) *Client
func (*Client) AddMiddleware ¶
func (c *Client) AddMiddleware(middleware Middleware)
func (*Client) GetMiddlewares ¶
func (c *Client) GetMiddlewares() []Middleware
func (*Client) GetRestClient ¶
func (*Client) GetRestConfig ¶
func (*Client) MakeRequest ¶
func (*Client) MakeRequestWithTrace ¶
func (*Client) SetMiddlewares ¶
func (c *Client) SetMiddlewares(middlewares ...Middleware)
type ClientOption ¶
type ClientOption func(*Client)
func WithMiddleware ¶
func WithMiddleware(middleware Middleware) ClientOption
func WithMiddlewares ¶
func WithMiddlewares(middlewares ...Middleware) ClientOption
func WithOTelConfig ¶
func WithOTelConfig(cfg *otel.Config) ClientOption
WithOTelConfig sets the OpenTelemetry configuration for the REST client When set, adds OTel tracing, metrics, and logging middleware automatically
func WithRestConfig ¶
func WithRestConfig(restConfig Config) ClientOption
type Config ¶
type Config struct {
RetryCount int `yaml:"retryCount" mapstructure:"retryCount"`
RetryWaitTime time.Duration `yaml:"retryWaitTime" mapstructure:"retryWaitTime"`
RetryMaxWaitTime time.Duration `yaml:"retryMaxWaitTime" mapstructure:"retryMaxWaitTime"`
Timeout time.Duration `yaml:"timeout" mapstructure:"timeout"`
// OpenTelemetry Configuration (optional - nil disables telemetry)
OTelConfig *otel.Config `yaml:"-" mapstructure:"-"` // Not serializable from config files
}
Config RestConfig contains configuration for REST client
func DefaultRestConfig ¶
func DefaultRestConfig() *Config
DefaultRestConfig returns a default REST configuration
type DatabaseLoggingMiddleware ¶
type DatabaseLoggingMiddleware struct{}
DatabaseLoggingMiddleware logs HTTP requests and responses to a database (placeholder implementation)
func NewDatabaseLoggingMiddleware ¶
func NewDatabaseLoggingMiddleware() *DatabaseLoggingMiddleware
NewDatabaseLoggingMiddleware creates a new DatabaseLoggingMiddleware instance
func (*DatabaseLoggingMiddleware) AfterRequest ¶
func (m *DatabaseLoggingMiddleware) AfterRequest(ctx context.Context, info RequestInfo)
AfterRequest logs the request to database (placeholder - just logs to console for now)
type ExecutionError ¶
ExecutionError represents an error during execution
func NewExecutionError ¶
func NewExecutionError(msg string, err error) *ExecutionError
func (*ExecutionError) Error ¶
func (e *ExecutionError) Error() string
func (*ExecutionError) Unwrap ¶
func (e *ExecutionError) Unwrap() error
type LoggingMiddleware ¶
type LoggingMiddleware struct{}
LoggingMiddleware logs HTTP requests and responses
func NewLoggingMiddleware ¶
func NewLoggingMiddleware() *LoggingMiddleware
NewLoggingMiddleware creates a new LoggingMiddleware instance
func (*LoggingMiddleware) AfterRequest ¶
func (m *LoggingMiddleware) AfterRequest(ctx context.Context, info RequestInfo)
AfterRequest logs the completion of the request with timing information
type Middleware ¶
type NoOpMiddleware ¶
type NoOpMiddleware struct{}
NoOpMiddleware is a middleware that does nothing - useful for testing and as a placeholder
func NewNoOpMiddleware ¶
func NewNoOpMiddleware() *NoOpMiddleware
NewNoOpMiddleware creates a new NoOpMiddleware instance
func (*NoOpMiddleware) AfterRequest ¶
func (m *NoOpMiddleware) AfterRequest(ctx context.Context, info RequestInfo)
AfterRequest does nothing
type OTelLoggingMiddleware ¶
type OTelLoggingMiddleware struct {
// contains filtered or unexported fields
}
OTelLoggingMiddleware implements structured logging with trace correlation for HTTP client
func NewOTelLoggingMiddleware ¶
func NewOTelLoggingMiddleware(cfg *pkgotel.Config) *OTelLoggingMiddleware
NewOTelLoggingMiddleware creates a new OpenTelemetry logging middleware
func (*OTelLoggingMiddleware) AfterRequest ¶
func (m *OTelLoggingMiddleware) AfterRequest(ctx context.Context, info RequestInfo)
AfterRequest logs the completion of the request with trace correlation
type OTelMetricsMiddleware ¶
type OTelMetricsMiddleware struct {
// contains filtered or unexported fields
}
OTelMetricsMiddleware implements metrics collection for HTTP client requests
func NewOTelMetricsMiddleware ¶
func NewOTelMetricsMiddleware(cfg *pkgotel.Config) *OTelMetricsMiddleware
NewOTelMetricsMiddleware creates a new OpenTelemetry metrics middleware
func (*OTelMetricsMiddleware) AfterRequest ¶
func (m *OTelMetricsMiddleware) AfterRequest(ctx context.Context, info RequestInfo)
AfterRequest records response metrics
func (*OTelMetricsMiddleware) BeforeRequest ¶
func (m *OTelMetricsMiddleware) BeforeRequest(ctx context.Context, method string, url string, body string, headers map[string]string) context.Context
BeforeRequest records request size metrics
func (*OTelMetricsMiddleware) RecordRetry ¶
func (m *OTelMetricsMiddleware) RecordRetry(ctx context.Context, method string, attempt int)
RecordRetry records a retry attempt (to be called by retry logic)
type OTelTracingMiddleware ¶
type OTelTracingMiddleware struct {
// contains filtered or unexported fields
}
OTelTracingMiddleware implements distributed tracing for HTTP client requests
func NewOTelTracingMiddleware ¶
func NewOTelTracingMiddleware(cfg *pkgotel.Config) *OTelTracingMiddleware
NewOTelTracingMiddleware creates a new OpenTelemetry tracing middleware
func (*OTelTracingMiddleware) AfterRequest ¶
func (m *OTelTracingMiddleware) AfterRequest(ctx context.Context, info RequestInfo)
AfterRequest ends the span and records the response status
type RequestInfo ¶
type ResourceNotFoundError ¶
func NewResourceNotFoundError ¶
func NewResourceNotFoundError(statusCode int, msg string, respBody string) *ResourceNotFoundError
func (*ResourceNotFoundError) Error ¶
func (e *ResourceNotFoundError) Error() string
type ResponseError ¶
func NewResponseError ¶
func NewResponseError(statusCode int, msg string, respBody string) *ResponseError
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
type ServerError ¶
func NewServerError ¶
func NewServerError(statusCode int, msg string, respBody string) *ServerError
NewServerError creates a new ServerError
func (*ServerError) Error ¶
func (e *ServerError) Error() string
type UnauthorizedError ¶
type UnauthorizedError struct {
}
UnauthorizedError represents an unauthorized error (HTTP 401)
func NewUnauthorizedError ¶
func NewUnauthorizedError(statusCode int, msg string, respBody string) *UnauthorizedError
NewUnauthorizedError creates a new UnauthorizedError
func (*UnauthorizedError) Error ¶
func (e *UnauthorizedError) Error() string