rest

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsClientError added in v1.3.2

func IsClientError(response *resty.Response) bool

func IsNotFound added in v1.3.2

func IsNotFound(response *resty.Response) bool

func IsServerError added in v1.3.2

func IsServerError(response *resty.Response) bool

func IsUnauthorized

func IsUnauthorized(response *resty.Response) bool

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(options ...ClientOption) *Client

func (*Client) AddMiddleware added in v1.3.3

func (c *Client) AddMiddleware(middleware Middleware)

func (*Client) GetMiddlewares added in v1.3.3

func (c *Client) GetMiddlewares() []Middleware

func (*Client) GetRestClient

func (c *Client) GetRestClient() *resty.Client

func (*Client) GetRestConfig

func (c *Client) GetRestConfig() *Config

func (*Client) HandleResponse

func (c *Client) HandleResponse(response *resty.Response) error

func (*Client) MakeRequest

func (c *Client) MakeRequest(ctx context.Context, method string, url string, body string, headers map[string]string) (*resty.Response, error)

func (*Client) MakeRequestWithTrace added in v1.3.3

func (c *Client) MakeRequestWithTrace(ctx context.Context, method string, url string, body string, headers map[string]string) (*resty.Response, error)

func (*Client) SetMiddlewares added in v1.3.3

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 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"`
}

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)

func (*DatabaseLoggingMiddleware) BeforeRequest

func (m *DatabaseLoggingMiddleware) BeforeRequest(ctx context.Context, method string, url string, body string, headers map[string]string) context.Context

BeforeRequest stores the start time in context for later use

type ExecutionError

type ExecutionError struct {
	Msg string
	Err error
}

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

func (*LoggingMiddleware) BeforeRequest

func (m *LoggingMiddleware) BeforeRequest(ctx context.Context, method string, url string, body string, headers map[string]string) context.Context

BeforeRequest logs the start of the request and stores the start time in context

type Middleware

type Middleware interface {
	BeforeRequest(ctx context.Context, method string, url string, body string, headers map[string]string) context.Context
	AfterRequest(ctx context.Context, info RequestInfo)
}

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

func (*NoOpMiddleware) BeforeRequest

func (m *NoOpMiddleware) BeforeRequest(ctx context.Context, method string, url string, body string, headers map[string]string) context.Context

BeforeRequest does nothing and returns the context unchanged

type RequestInfo

type RequestInfo struct {
	Method     string
	URL        string
	Headers    map[string]string
	Body       string
	StartTime  time.Time
	EndTime    time.Time
	Duration   time.Duration
	StatusCode int
	Response   string
	Error      error
	TraceInfo  resty.TraceInfo
}

type ResourceNotFoundError

type ResourceNotFoundError struct {
	StatusCode int
	Msg        string
	RespBody   string
}

func NewResourceNotFoundError

func NewResourceNotFoundError(statusCode int, msg string, respBody string) *ResourceNotFoundError

func (*ResourceNotFoundError) Error

func (e *ResourceNotFoundError) Error() string

type ResponseError

type ResponseError struct {
	StatusCode int
	Msg        string
	RespBody   string
}

func NewResponseError

func NewResponseError(statusCode int, msg string, respBody string) *ResponseError

func (*ResponseError) Error

func (e *ResponseError) Error() string

type ServerError

type ServerError struct {
	StatusCode int
	Msg        string
	RespBody   string
}

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 {
	StatusCode int
	Msg        string
	RespBody   string
}

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

Jump to

Keyboard shortcuts

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