timeout

package module
v0.0.0-...-ba36313 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2016 License: MIT Imports: 4 Imported by: 1

README

timeout

Build Status Coverage Status

HTTP timeout middleware for Go.

Installation

go get -u github.com/go-http-utils/timeout

Documentation

API documentation can be found here: https://godoc.org/github.com/go-http-utils/timeout

Usage

import (
  "github.com/go-http-utils/timeout"
)
mux := http.NewServeMux()
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
  res.Write([]byte("Hello World"))
})

http.ListenAndServe(":8080", timeout.Handler(mux, time.Second*10, timeout.DefaultTimeoutHandler))

Documentation

Overview

Example
package main

import (
	"net/http"
	"time"

	"github.com/go-http-utils/timeout"
)

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
		res.Write([]byte("Hello World"))
	})

	http.ListenAndServe(":8080", timeout.Handler(mux, time.Second*10, timeout.DefaultTimeoutHandler))
}

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultTimeoutHandler = http.HandlerFunc(
	func(res http.ResponseWriter, req *http.Request) {
		res.WriteHeader(http.StatusGatewayTimeout)
		res.Write([]byte("Service timeout"))
	})

DefaultTimeoutHandler is a convenient timeout handler which simply returns "504 Service timeout".

View Source
var Version = "0.1.0"

Version is this package's version.

Functions

func Handler

func Handler(h http.Handler, timeout time.Duration, timeoutHandler http.Handler) http.Handler

Handler wraps the http.Handler h with timeout support.

Types

This section is empty.

Jump to

Keyboard shortcuts

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