ekko: helper to setup labstack echo with logging, tracing, etc

This commit is contained in:
2024-09-20 21:47:10 -07:00
parent 8e898d9c59
commit 3f3fb29bc9
5 changed files with 223 additions and 2 deletions

40
ekko/options.go Normal file
View File

@@ -0,0 +1,40 @@
package ekko
import (
"github.com/labstack/echo/v4"
"github.com/prometheus/client_golang/prometheus"
)
type Ekko struct {
name string
prom prometheus.Registerer
port int
routeFn func(e *echo.Echo) error
otelmiddleware echo.MiddlewareFunc
}
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 WithOtelMiddleware(mw echo.MiddlewareFunc) func(*Ekko) {
return func(ek *Ekko) {
ek.otelmiddleware = mw
}
}