chore(bots): re-structure grpc folder.

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi.Wu
2022-08-22 21:12:39 +08:00
committed by Jason Song
parent 2cba8fafd8
commit e4e41a8065
10 changed files with 133 additions and 122 deletions

View File

@ -5,18 +5,32 @@
package bots
import (
"log"
"net/http"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/bots/grpc"
)
func grpcHandler(h http.Handler) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Println("protocol version:", r.Proto)
h.ServeHTTP(w, r)
})
}
func gRPCRouter(r *web.Route, fn grpc.RouteFn) {
p, h := fn()
r.Post(p+"{name}", grpcHandler(h))
}
func Routes(r *web.Route) {
// socket connection
r.Get("/socket", socketServe)
// runner service
runnerServiceRoute(r)
// ping service
pingServiceRoute(r)
// health service
healthServiceRoute(r)
// grpcv1 and v1alpha service
grpcServiceRoute(r)
gRPCRouter(r, grpc.V1Route)
gRPCRouter(r, grpc.V1AlphaRoute)
gRPCRouter(r, grpc.HealthRoute)
gRPCRouter(r, grpc.PingRoute)
gRPCRouter(r, grpc.RunnerRoute)
}