1
1
mirror of https://github.com/go-gitea/gitea synced 2025-11-01 11:58:25 +00:00

chore: update grpc router path

This commit is contained in:
Jason Song
2022-11-22 18:24:01 +08:00
parent 48f5c152b9
commit e346581344
4 changed files with 24 additions and 23 deletions

View File

@@ -5,31 +5,26 @@
package bots
import (
"context"
"net/http"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/bots/grpc"
)
func grpcHandler(h http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Trace("protocol version: %v", r.Proto)
h.ServeHTTP(w, r)
func Routes(_ context.Context, prefix string) *web.Route {
m := web.NewRoute()
for _, fn := range []grpc.RouteFn{
grpc.V1Route,
grpc.V1AlphaRoute,
grpc.HealthRoute,
grpc.PingRoute,
grpc.RunnerRoute,
} {
path, handler := fn()
m.Post(path+"*", http.StripPrefix(prefix, handler).ServeHTTP)
}
}
func gRPCRouter(r *web.Route, fn grpc.RouteFn) {
p, h := fn()
r.Post(p+"{name}", grpcHandler(h))
}
func Routes(r *web.Route) *web.Route {
gRPCRouter(r, grpc.V1Route)
gRPCRouter(r, grpc.V1AlphaRoute)
gRPCRouter(r, grpc.HealthRoute)
gRPCRouter(r, grpc.PingRoute)
gRPCRouter(r, grpc.RunnerRoute)
return r
return m
}