common/ekko/options.go

74 lines
1.4 KiB
Go
Raw Normal View History

package ekko
import (
"time"
"github.com/labstack/echo/v4"
2024-12-02 00:45:49 +00:00
"github.com/labstack/echo/v4/middleware"
"github.com/prometheus/client_golang/prometheus"
2024-10-12 18:39:16 +00:00
slogecho "github.com/samber/slog-echo"
)
type Ekko struct {
name string
prom prometheus.Registerer
port int
routeFn func(e *echo.Echo) error
2024-10-12 18:39:16 +00:00
logFilters []slogecho.Filter
otelmiddleware echo.MiddlewareFunc
2024-12-02 00:45:49 +00:00
gzipConfig *middleware.GzipConfig
writeTimeout time.Duration
readHeaderTimeout time.Duration
}
type RouteFn func(e *echo.Echo) error
func WithPort(port int) func(*Ekko) {
return func(ek *Ekko) {
ek.port = port
}
}
func WithPrometheus(reg prometheus.Registerer) func(*Ekko) {
return func(ek *Ekko) {
ek.prom = reg
}
}
func WithEchoSetup(rfn RouteFn) func(*Ekko) {
return func(ek *Ekko) {
ek.routeFn = rfn
}
}
2024-10-12 18:39:16 +00:00
func WithLogFilters(f []slogecho.Filter) func(*Ekko) {
return func(ek *Ekko) {
ek.logFilters = f
}
}
func WithOtelMiddleware(mw echo.MiddlewareFunc) func(*Ekko) {
return func(ek *Ekko) {
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
}
}
2024-12-02 00:45:49 +00:00
func WithGzipConfig(gzipConfig *middleware.GzipConfig) func(*Ekko) {
return func(ek *Ekko) {
ek.gzipConfig = gzipConfig
}
}