Documentation
¶
Index ¶
- Constants
- func Error(w http.ResponseWriter, status int)
- func GetRequestHeaderAPIKey(req *http.Request) string
- func GetRequestHeaderSessionID(req *http.Request) string
- func GetRequestIP(r *http.Request) string
- func NewHTTPClient(opts ...ClientOption) *http.Client
- func NewRetryTransport(base http.RoundTripper, config RetryConfig) http.RoundTripper
- func NewTransport() http.RoundTripper
- func ParseRetryAfter(resp *http.Response, maxRetryAfter time.Duration) time.Duration
- func SetHeaderContentTypeApplicationJSON(w http.ResponseWriter)
- func SetHeaderContentTypeTextHTMLCharsetUTF8(w http.ResponseWriter)
- func SetHeaderRequestID(w http.ResponseWriter, requestID string)
- func SetHeaderRetryAfter(w http.ResponseWriter, retryAfter time.Duration)
- func SetRequestHeaderAPIKey(req *http.Request, apiKey string)
- func SetRequestHeaderSessionID(req *http.Request, sessionID string)
- func WriteJSON(w http.ResponseWriter, status int, data any)
- func WriteNoContent(w http.ResponseWriter)
- func WriteOK(w http.ResponseWriter, data any)
- func WriteRateLimitError(w http.ResponseWriter, err *RateLimitError)
- type ClientOption
- type RateLimitError
- type RetryConfig
Constants ¶
View Source
const ( XForwardedFor = "X-Forwarded-For" XContentTypeOpts = "X-Content-Type-Options" XFrameOpts = "X-Frame-Options" XXSSProtection = "X-Xss-Protection" ReferrerPolicy = "Referrer-Policy" )
View Source
const ( ContentType = "Content-Type" ContentLength = "Content-Length" ContentEncoding = "Content-Encoding" AcceptEncoding = "Accept-Encoding" Vary = "Vary" XRateLimitReason = "X-Ratelimit-Reason" XSessionID = "X-Session-Id" XAPIKey = "X-Api-Key" //nolint:gosec // this is a header name, not a credential )
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, status int)
func GetRequestHeaderAPIKey ¶
func GetRequestIP ¶
func NewHTTPClient ¶
func NewHTTPClient(opts ...ClientOption) *http.Client
func NewRetryTransport ¶ added in v0.1.7
func NewRetryTransport(base http.RoundTripper, config RetryConfig) http.RoundTripper
NewRetryTransport creates a new retry transport wrapping the given transport.
func NewTransport ¶
func NewTransport() http.RoundTripper
NewTransport returns an http.RoundTripper with standard thoop headers.
func ParseRetryAfter ¶ added in v0.1.7
ParseRetryAfter parses the Retry-After header from a response. Returns 0 if the header is missing or invalid. This is exported for use by SSE clients that handle their own retry logic.
func SetHeaderContentTypeApplicationJSON ¶
func SetHeaderContentTypeApplicationJSON(w http.ResponseWriter)
func SetHeaderContentTypeTextHTMLCharsetUTF8 ¶ added in v0.1.8
func SetHeaderContentTypeTextHTMLCharsetUTF8(w http.ResponseWriter)
func SetHeaderRequestID ¶
func SetHeaderRequestID(w http.ResponseWriter, requestID string)
func SetHeaderRetryAfter ¶
func SetHeaderRetryAfter(w http.ResponseWriter, retryAfter time.Duration)
func SetRequestHeaderAPIKey ¶ added in v0.0.11
func WriteNoContent ¶
func WriteNoContent(w http.ResponseWriter)
func WriteOK ¶
func WriteOK(w http.ResponseWriter, data any)
func WriteRateLimitError ¶
func WriteRateLimitError(w http.ResponseWriter, err *RateLimitError)
Types ¶
type ClientOption ¶
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
type RateLimitError ¶
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
type RetryConfig ¶ added in v0.1.7
type RetryConfig struct {
MaxAttempts uint // Maximum number of retry attempts (default: 3)
MaxRetryAfter time.Duration // Maximum Retry-After to respect (default: 30s)
InitialBackoff time.Duration // Initial backoff duration (default: 1s)
MaxBackoff time.Duration // Maximum backoff duration (default: 10s)
BackoffFactor float64 // Backoff multiplier (default: 2.0)
}
RetryConfig configures the retry transport behavior.
func DefaultRetryConfig ¶ added in v0.1.7
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns sensible defaults for retry behavior.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.