Documentation
¶
Index ¶
- type Client
- type ClientOption
- type Request
- func (r *Request) Build(baseURL string) (*http.Request, error)
- func (r *Request) WithBody(body interface{}) *Request
- func (r *Request) WithHeader(key, value string) *Request
- func (r *Request) WithQueryParam(key, value string) *Request
- func (r *Request) WithQueryParams(params map[string]string) *Request
- type Response
- func (r *Response) GetBody() ([]byte, error)
- func (r *Response) GetBodyAsJSON(v interface{}) error
- func (r *Response) GetBodyAsString() (string, error)
- func (r *Response) GetContentTransferTimeMillis() int64
- func (r *Response) GetDNSLookupTimeMillis() int64
- func (r *Response) GetHeader(key string) string
- func (r *Response) GetResponseTimeMillis() int64
- func (r *Response) GetTCPConnectTimeMillis() int64
- func (r *Response) GetTLSHandshakeTimeMillis() int64
- func (r *Response) GetTimeToFirstByteMillis() int64
- func (r *Response) GetTotalTimeMillis() int64
- func (r *Response) IsClientError() bool
- func (r *Response) IsRedirect() bool
- func (r *Response) IsServerError() bool
- func (r *Response) IsSuccess() bool
- type TimingInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an HTTP client with customizable options
func NewClient ¶
func NewClient(options ...ClientOption) *Client
NewClient creates a new HTTP client with the given options
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is a function that configures a Client
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL sets the base URL for the client
func WithHeader ¶
func WithHeader(key, value string) ClientOption
WithHeader adds a header to the client
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets the timeout for the client
type Request ¶
type Request struct {
Method string
Path string
QueryParams url.Values
Headers map[string]string
Body interface{}
}
Request represents an HTTP request
func NewRequest ¶
NewRequest creates a new HTTP request
func (*Request) WithHeader ¶
WithHeader adds a header to the request
func (*Request) WithQueryParam ¶
WithQueryParam adds a query parameter to the request
type Response ¶
type Response struct {
StatusCode int
Status string
Headers http.Header
Body io.ReadCloser
ResponseTime time.Duration
Timing TimingInfo
// contains filtered or unexported fields
}
Response represents an HTTP response
func (*Response) GetBodyAsJSON ¶
GetBodyAsJSON unmarshals the response body into the provided interface
func (*Response) GetBodyAsString ¶
GetBodyAsString returns the response body as a string
func (*Response) GetContentTransferTimeMillis ¶
GetContentTransferTimeMillis returns the content transfer time in milliseconds
func (*Response) GetDNSLookupTimeMillis ¶
GetDNSLookupTimeMillis returns the DNS lookup time in milliseconds
func (*Response) GetResponseTimeMillis ¶
GetResponseTimeMillis returns the response time in milliseconds
func (*Response) GetTCPConnectTimeMillis ¶
GetTCPConnectTimeMillis returns the TCP connection time in milliseconds
func (*Response) GetTLSHandshakeTimeMillis ¶
GetTLSHandshakeTimeMillis returns the TLS handshake time in milliseconds
func (*Response) GetTimeToFirstByteMillis ¶
GetTimeToFirstByteMillis returns the time to first byte in milliseconds
func (*Response) GetTotalTimeMillis ¶
GetTotalTimeMillis returns the total time in milliseconds
func (*Response) IsClientError ¶
IsClientError returns true if the response status code is in the 4xx range
func (*Response) IsRedirect ¶
IsRedirect returns true if the response status code is in the 3xx range
func (*Response) IsServerError ¶
IsServerError returns true if the response status code is in the 5xx range
type TimingInfo ¶
type TimingInfo struct {
// Time when the request started
StartTime time.Time
// DNS lookup time
DNSLookupTime time.Duration
// TCP connection time
TCPConnectTime time.Duration
// TLS handshake time (for HTTPS)
TLSHandshakeTime time.Duration
// Time to first byte (TTFB)
TimeToFirstByte time.Duration
// Content transfer time
ContentTransferTime time.Duration
// Total response time
TotalTime time.Duration
}
TimingInfo stores detailed timing information for an HTTP request