support runtime.ServeMux opts for grpc-gateway
All checks were successful
Build and Publish / release (push) Has been skipped
Build and Publish / check-chart (push) Successful in 10s
Build and Publish / helm-release (push) Has been skipped

This commit is contained in:
2025-03-25 17:05:59 -04:00
parent 1e481627e3
commit f201ac1fca
10 changed files with 78 additions and 6 deletions

View File

@@ -318,6 +318,18 @@ func (aw *AmbientWeather) enrichStation(update *weather.WeatherUpdate) {
}
}
func (aw *AmbientWeather) GetLogger() *zerolog.Logger {
aw.RLock()
defer aw.RUnlock()
return aw.l
}
func (aw *AmbientWeather) GetCtx() context.Context {
aw.RLock()
defer aw.RUnlock()
return aw.appCtx
}
func (aw *AmbientWeather) GetRecorder() *recorder.WeatherRecorder {
aw.RLock()
defer aw.RUnlock()

33
pkg/ambient/app.go Normal file
View File

@@ -0,0 +1,33 @@
package ambient
import (
"context"
"net/http"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
)
func (aw *AmbientWeather) GetGatewayOpts() []runtime.ServeMuxOption {
return []runtime.ServeMuxOption{
runtime.WithMiddlewares(func(hf runtime.HandlerFunc) runtime.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
aw.GetLogger().Trace().
Any("pathParams", pathParams).
Msg("inbound request called")
}
}),
runtime.WithRoutingErrorHandler(
func(
ctx context.Context, mux *runtime.ServeMux, mshl runtime.Marshaler,
w http.ResponseWriter, r *http.Request, code int,
) {
aw.GetLogger().Trace().
Int("code", code).
Str("pattern", r.Pattern).
Msg("requesting grpc-gateway route")
// Pass back to default
runtime.DefaultRoutingErrorHandler(ctx, mux, mshl, w, r, code)
}),
}
}