ekko: configurable read write and readheader timeouts
This commit is contained in:
parent
152be9d956
commit
68bd4d8904
11
ekko/ekko.go
11
ekko/ekko.go
@ -20,7 +20,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func New(name string, options ...func(*Ekko)) (*Ekko, error) {
|
func New(name string, options ...func(*Ekko)) (*Ekko, error) {
|
||||||
ek := &Ekko{}
|
ek := &Ekko{
|
||||||
|
writeTimeout: 60 * time.Second,
|
||||||
|
readHeaderTimeout: 30 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
for _, o := range options {
|
for _, o := range options {
|
||||||
o(ek)
|
o(ek)
|
||||||
}
|
}
|
||||||
@ -68,9 +72,8 @@ func (ek *Ekko) setup(ctx context.Context) (*echo.Echo, error) {
|
|||||||
|
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|
||||||
// todo: make these an option?
|
e.Server.ReadHeaderTimeout = ek.readHeaderTimeout
|
||||||
e.Server.ReadTimeout = 30 * time.Second
|
e.Server.WriteTimeout = ek.writeTimeout
|
||||||
e.Server.WriteTimeout = 60 * time.Second
|
|
||||||
|
|
||||||
e.Server.BaseContext = func(_ net.Listener) context.Context {
|
e.Server.BaseContext = func(_ net.Listener) context.Context {
|
||||||
return ctx
|
return ctx
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package ekko
|
package ekko
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
slogecho "github.com/samber/slog-echo"
|
slogecho "github.com/samber/slog-echo"
|
||||||
@ -13,6 +15,9 @@ type Ekko struct {
|
|||||||
routeFn func(e *echo.Echo) error
|
routeFn func(e *echo.Echo) error
|
||||||
logFilters []slogecho.Filter
|
logFilters []slogecho.Filter
|
||||||
otelmiddleware echo.MiddlewareFunc
|
otelmiddleware echo.MiddlewareFunc
|
||||||
|
|
||||||
|
writeTimeout time.Duration
|
||||||
|
readHeaderTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type RouteFn func(e *echo.Echo) error
|
type RouteFn func(e *echo.Echo) error
|
||||||
@ -46,3 +51,15 @@ func WithOtelMiddleware(mw echo.MiddlewareFunc) func(*Ekko) {
|
|||||||
ek.otelmiddleware = mw
|
ek.otelmiddleware = mw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithWriteTimeout(t time.Duration) func(*Ekko) {
|
||||||
|
return func(ek *Ekko) {
|
||||||
|
ek.writeTimeout = t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithReadHeaderTimeout(t time.Duration) func(*Ekko) {
|
||||||
|
return func(ek *Ekko) {
|
||||||
|
ek.readHeaderTimeout = t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user