client

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultUserAgent is the default User-Agent string
	DefaultUserAgent = "urlmap/1.0.0 (+https://github.com/aoshimash/urlmap)"
	// DefaultTimeout is the default HTTP timeout
	DefaultTimeout = 30 * time.Second
	// DefaultRetryCount is the default number of retry attempts
	DefaultRetryCount = 3
	// DefaultRetryWaitTime is the default wait time between retries
	DefaultRetryWaitTime = 1 * time.Second
	// DefaultRetryMaxWaitTime is the maximum wait time between retries
	DefaultRetryMaxWaitTime = 5 * time.Second
)

Variables

This section is empty.

Functions

func GetStatusMessage

func GetStatusMessage(resp *resty.Response) string

GetStatusMessage returns a human-readable status message for the response

func IsClientError

func IsClientError(resp *resty.Response) bool

IsClientError checks if the HTTP response indicates a client error (4xx status code)

func IsServerError

func IsServerError(resp *resty.Response) bool

IsServerError checks if the HTTP response indicates a server error (5xx status code)

func IsSuccess

func IsSuccess(resp *resty.Response) bool

IsSuccess checks if the HTTP response indicates success (2xx status code)

Types

type Client

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

Client wraps the Resty client with additional functionality

func NewClient

func NewClient(config *Config) *Client

NewClient creates a new HTTP client with the given configuration

func NewDefaultClient

func NewDefaultClient() *Client

NewDefaultClient creates a new HTTP client with default configuration

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) (*resty.Response, error)

Get performs a GET request to the specified URL

func (*Client) GetClient

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

GetClient returns the underlying Resty client for advanced usage

func (*Client) GetConfig

func (c *Client) GetConfig() *Config

GetConfig returns the client configuration

func (*Client) GetWithHeaders

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

GetWithHeaders performs a GET request with custom headers

func (*Client) Post

func (c *Client) Post(ctx context.Context, url string, body interface{}) (*resty.Response, error)

Post performs a POST request with the given body

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration)

SetTimeout updates the request timeout

func (*Client) SetUserAgent

func (c *Client) SetUserAgent(userAgent string)

SetUserAgent updates the User-Agent string

type Config

type Config struct {
	UserAgent        string
	Timeout          time.Duration
	RetryCount       int
	RetryWaitTime    time.Duration
	RetryMaxWaitTime time.Duration
}

Config holds the HTTP client configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default client configuration

Jump to

Keyboard shortcuts

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