# README
Timeout
Timeout wraps a handler and aborts the process of the handler if the timeout is reached.
Example
package main
import (
"net/http"
"time"
"github.com/gin-contrib/timeout"
"github.com/gin-gonic/gin"
)
func emptySuccessResponse(c *gin.Context) {
time.Sleep(200 * time.Microsecond)
c.String(http.StatusOK, "")
}
func main() {
r := gin.New()
r.GET("/", timeout.New(
timeout.WithTimeout(100*time.Microsecond),
timeout.WithHandler(emptySuccessResponse),
))
// Listen and Server in 0.0.0.0:8080
r.Run(":8080")
}
custom error response
Add new error response func:
func testResponse(c *gin.Context) {
c.String(http.StatusRequestTimeout, "test response")
}
Add WithResponse
option.
r.GET("/", timeout.New(
WithTimeout(100*time.Microsecond),
WithHandler(emptySuccessResponse),
WithResponse(testResponse),
))
# Packages
No description provided by the author
# Functions
New wraps a handler and aborts the process of the handler if the timeout is reached.
NewWriter will return a timeout.Writer pointer.
WithHandler add gin handler.
WithResponse add gin handler.
WithTimeout set timeout.
# Structs
BufferPool is Pool of *bytes.Buffer.
Timeout struct.
Writer is a writer with memory buffer.
# Type aliases
Option for timeout.