Last active
August 6, 2021 11:35
-
-
Save percybolmer/92e63bbf45301f8b2d2f9bb51488a934 to your computer and use it in GitHub Desktop.
Grpc -> Htttp Multipelxer middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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