timeout

package module
v0.0.0-...-203087d Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 4 Imported by: 0

README

timeout-transport

Go Reference

A simple Golang http.Transport which injects a fixed timeout to each request

Usage

package main

import (
	"log"
	"net/http"
	"time"

	timeout "github.com/bored-engineer/timeout-transport"
)

func main() {
	client := &http.Client{
		Transport: &timeout.Transport{
			// Transport is optional, defaults to http.DefaultTransport
			Timeout: 5 * time.Second,
		},
	}

	resp, err := client.Get("https://example.com")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
}

Documentation

Overview

Package timeout provides a http.RoundTripper which injects a fixed timeout into each request.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Transport

type Transport struct {
	// Transport is the underlying http.RoundTripper used to perform requests.
	// If nil, http.DefaultTransport is used.
	Transport http.RoundTripper

	// Timeout is the maximum duration allowed for the round trip, starting
	// when RoundTrip is called and ending only once the response body is closed.
	Timeout time.Duration
}

Transport wraps another http.RoundTripper, bounding the entire round trip (including reading the response body) to a fixed Timeout via the request's context.

func (*Transport) RoundTrip

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

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

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