httpkit

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 2 Imported by: 0

README

go-httpkit

A lightweight HTTP client library for Go with middleware support and functional options built on the standard library.

Installation

go get codeberg.org/jyggen/go-httpkit

Usage

Basic Client
client := httpkit.New()
resp, err := client.Get("https://example.com")
With Options
client := httpkit.New(
    httpkit.WithTimeout(30 * time.Second),
    httpkit.WithUserAgent("MyBot/1.0"),
    httpkit.WithSkipRedirects(),
)
With Middleware
logger := func(next httpkit.Middleware) httpkit.Middleware {
    return func(req *http.Request) (*http.Response, error) {
        log.Printf("Request: %s %s", req.Method, req.URL)
        return next(req)
    }
}

client := httpkit.New(httpkit.WithMiddleware(logger))
From Existing Client
existing := &http.Client{Timeout: 10 * time.Second}
client := httpkit.NewFromClient(existing, httpkit.WithUserAgent("MyBot/1.0"))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

func NewFromClient

func NewFromClient(client *http.Client, options ...Option) *http.Client

Types

type Middleware

type Middleware func(*http.Request) (*http.Response, error)

type MiddlewareFunc

type MiddlewareFunc func(Middleware) Middleware

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithMiddleware

func WithMiddleware(middleware MiddlewareFunc) Option

func WithSkipRedirects

func WithSkipRedirects() Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

func WithTransport

func WithTransport(rt http.RoundTripper) Option

func WithUserAgent

func WithUserAgent(userAgent string) Option

type OptionFunc

type OptionFunc func(*http.Client)

Jump to

Keyboard shortcuts

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