• v1.0.0 caa397591e

    Rene Nochebuena released this 2026-05-29 10:07:06 -06:00 | 0 commits to main since this release

    v1.0.0

    code.nochebuena.dev/einherjar/httpclient


    Architecture Decisions Resolved

    Decision Outcome
    Retry library avast/retry-go — idiomatic Go, supports condition functions
    Circuit breaker library sony/gobreaker — battle-tested, simple state machine
    Provider interface Single Do method — narrowest useful contract; consumers compose behaviour
    Generic JSON helpers DoJSON[T] and DoJSONRequest[Req, Resp] — reduce boilerplate without hiding the client

    API

    import "code.nochebuena.dev/einherjar/httpclient"
    
    // Package sentinel
    // Module identifies this package to observability systems.
    // httpclient returns a Provider — not registered with the launcher as a lifecycle component.
    // Register Module manually with any version registry if needed.
    var Module observability.Identifiable
    
    // Interface
    type Provider interface {
        Do(req *http.Request) (*http.Response, error)
    }
    
    // Config
    type Config struct {
        Name        string        `env:"EINHERJAR_HTTP_CLIENT_NAME" envDefault:"http"`
        Timeout     time.Duration `env:"EINHERJAR_HTTP_TIMEOUT"     envDefault:"30s"`
        DialTimeout time.Duration `env:"EINHERJAR_HTTP_DIAL_TIMEOUT" envDefault:"5s"`
        MaxRetries  uint          `env:"EINHERJAR_HTTP_MAX_RETRIES"  envDefault:"3"`
        RetryDelay  time.Duration `env:"EINHERJAR_HTTP_RETRY_DELAY"  envDefault:"1s"`
        CBThreshold uint32        `env:"EINHERJAR_HTTP_CB_THRESHOLD" envDefault:"10"`
        CBTimeout   time.Duration `env:"EINHERJAR_HTTP_CB_TIMEOUT"   envDefault:"1m"`
    }
    func DefaultConfig() Config
    
    // Constructors
    func New(logger logging.Logger, cfg Config) Provider
    func NewWithDefaults(logger logging.Logger) Provider
    
    // Helpers
    func DoJSON[T any](ctx context.Context, client Provider, req *http.Request) (*T, error)
    func DoJSONRequest[Req, Resp any](ctx context.Context, client Provider, method, rawURL string, body Req) (*Resp, error)
    func MapStatusToError(code int, msg string) error
    

    Install

    go get code.nochebuena.dev/einherjar/httpclient@v1.0.0
    

    Dependencies

    Module Version Role
    code.nochebuena.dev/einherjar/contracts v1.0.0 logging.Logger
    code.nochebuena.dev/einherjar/core v1.0.0 xerrors
    github.com/avast/retry-go/v4 v4.3.4 Retry with configurable conditions
    github.com/sony/gobreaker v1.0.0 Circuit breaker
    Downloads