Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active August 6, 2021 11:35
Show Gist options
  • Save percybolmer/92e63bbf45301f8b2d2f9bb51488a934 to your computer and use it in GitHub Desktop.
Save percybolmer/92e63bbf45301f8b2d2f9bb51488a934 to your computer and use it in GitHub Desktop.
Grpc -> Htttp Multipelxer middleware
type grpcMultiplexer struct {
*grpcweb.WrappedGrpcServer
}
// Handler is used to route requests to either grpc or to regular http
func (m *grpcMultiplexer) Handler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if m.IsGrpcWebRequest(r) {
m.ServeHTTP(w, r)
return
}
next.ServeHTTP(w, r)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment