Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHTTPClient ¶
NewHTTPClient returns a fully initialized http.Client that uses the provided cache to store responses. It uses the default http.Client as a base, and replaces the transport with a new, caching RoundTripper.
Types ¶
type HTTPCache ¶
type HTTPCache struct { Adapter // contains filtered or unexported fields }
func NewOtterCache ¶
func NewOtterCache(cache OtterCache, options ...Option) HTTPCache
type OtterCache ¶
type OtterCache interface { Get(key string) (string, bool) Set(key string, value string, ttl time.Duration) bool Delete(key string) Close() }
OtterCache mimics the public API of the Otter cache so that we don't have to import it into this library. https://github.com/maypok86/otter
type RoundTripper ¶
type RoundTripper struct {
// contains filtered or unexported fields
}
RoundTripper implements the http.RoundTripper interface, that is used by the http.Client to cache outbound HTTP requests. https://echorand.me/posts/go-http-client-middleware/ https://lanre.wtf/blog/2017/07/24/roundtripper-go https://pkgo.dev/net/http#RoundTripper
func NewRoundTripper ¶
func NewRoundTripper(cache *HTTPCache) RoundTripper
NewRoundTripper returns a fully initialized RoundTripper
func (RoundTripper) RoundTrip ¶
RoundTrip implements the http.RoundTripper interface, which replaces the http.Client's default behavior with a caching mechanism.
func (*RoundTripper) SetCache ¶
func (roundTripper *RoundTripper) SetCache(cache *HTTPCache)
SetCache replaces the existing cache with a new one
func (*RoundTripper) SetClient ¶
func (roundTripper *RoundTripper) SetClient(client *http.Client)
SetClient replaces the default http.Client with a custom client