timeout

package
v2.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 6 Imported by: 0

README

gentleman/timeout Build Status GoDoc Go Report Card

gentleman's plugin to easily define HTTP timeouts per specific phase in the HTTP connection live cycle.

Installation

go get -u gitee.com/trako/gentleman/plugins/timeout

API

See godoc reference.

Example

package main

import (
  "fmt"
  "gopkg.in/h2non/gentleman.v2"
  "gitee.com/trako/gentleman/plugins/timeout"
  "time"
)

func main() {
  // Create a new client
  cli := gentleman.New()

  // Define the max timeout for the whole HTTP request
  cli.Use(timeout.Request(10 * time.Second))

  // Define dial specific timeouts
  cli.Use(timeout.Dial(5*time.Second, 30*time.Second))

  // Perform the request
  res, err := cli.Request().URL("http://httpbin.org/headers").Send()
  if err != nil {
    fmt.Printf("Request error: %s\n", err)
    return
  }
  if !res.Ok {
    fmt.Printf("Invalid server response: %d\n", res.StatusCode)
    return
  }

  fmt.Printf("Status: %d\n", res.StatusCode)
  fmt.Printf("Body: %s", res.String())
}

License

MIT - Tomas Aparicio

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(timeouts Timeouts) p.Plugin

All defines all the timeout types for the outgoing request

func Dial

func Dial(timeout, keepAlive time.Duration) p.Plugin

Dial defines the maximum amount of time waiting for network dialing

func Request

func Request(timeout time.Duration) p.Plugin

Request defines the maximum amount of time a whole request process (including dial / request / redirect) can take.

func TLS

func TLS(timeout time.Duration) p.Plugin

TLS defines the maximum amount of time waiting for a TLS handshake

Types

type Timeouts

type Timeouts struct {
	// Request represents the total timeout including dial / request / redirect steps
	Request time.Duration

	// TLS represents the maximum amount of time for TLS handshake process
	TLS time.Duration

	// Dial represents the maximum amount of time for dialing process
	Dial time.Duration

	// KeepAlive represents the maximum amount of time to keep alive the socket
	KeepAlive time.Duration
}

Timeouts represents the supported timeouts

Jump to

Keyboard shortcuts

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