base

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package base provides a base HTTP client with logging middleware for calling other services.

Index

Constants

View Source
const (
	// RateLimitWarningThreshold is the number of remaining requests before a warning is logged.
	RateLimitWarningThreshold = 5
	// RateLimitWarningMsg is the message logged when the number of remaining requests is below the warning threshold.
	RateLimitWarningMsg = "API requests nearing rate limit"
	// RateLimitHitMsg is the message logged when the number of remaining requests is 0.
	RateLimitHitMsg = "API rate limit hit, sleeping until limit reset"
)

Variables

This section is empty.

Functions

func NewClient

func NewClient(options ...Option) *http.Client

NewClient creates a new base HTTP client with logging middleware

func NewTransport

func NewTransport(options ...Option) http.RoundTripper

NewTransport creates a new base transport with logging middleware for use as the base transport for other clients

Types

type LoggingTransport

type LoggingTransport struct {
	// Base is the underlying HTTP transport
	Base http.RoundTripper
	// Logger is the logger to use for logging
	Logger zerolog.Logger
	// Component identifies the service making the request
	Component string
}

LoggingTransport is an HTTP transport that logs requests and responses

func (*LoggingTransport) RoundTrip

func (t *LoggingTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface

type Option

type Option func(*baseOptions)

Option can modify how the base client works

func WithBaseTransport

func WithBaseTransport(base http.RoundTripper) Option

WithBaseTransport sets the base transport to use for the client

func WithComponent

func WithComponent(component string) Option

WithComponent sets the component used

func WithLogger

func WithLogger(logger zerolog.Logger) Option

WithLogger sets the logger to use for logging requests and responses

Jump to

Keyboard shortcuts

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