66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
package ekko
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
slogecho "github.com/samber/slog-echo"
|
|
)
|
|
|
|
type Ekko struct {
|
|
name string
|
|
prom prometheus.Registerer
|
|
port int
|
|
routeFn func(e *echo.Echo) error
|
|
logFilters []slogecho.Filter
|
|
otelmiddleware echo.MiddlewareFunc
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|