Files
gin-contrib/timeout/option.go
T
2024-03-29 11:40:39 +03:00

44 lines
751 B
Go

package timeout
import (
"net/http"
"time"
"gitverse.ru/andoma/gin"
)
// Option for timeout
type Option func(*Timeout)
// WithTimeout set timeout
func WithTimeout(timeout time.Duration) Option {
return func(t *Timeout) {
t.timeout = timeout
}
}
// WithHandler add gin handler
func WithHandler(h gin.HandlerFunc) Option {
return func(t *Timeout) {
t.handler = h
}
}
// WithResponse add gin handler
func WithResponse(h gin.HandlerFunc) Option {
return func(t *Timeout) {
t.response = h
}
}
func defaultResponse(c *gin.Context) {
c.String(http.StatusRequestTimeout, http.StatusText(http.StatusRequestTimeout))
}
// Timeout struct
type Timeout struct {
timeout time.Duration
handler gin.HandlerFunc
response gin.HandlerFunc
}