chore(proto): Add ping service

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2022-08-13 21:41:31 +08:00
committed by Jason Song
parent 0e79fc556a
commit ef3a74a1ba
5 changed files with 150 additions and 70 deletions

View File

@ -6,47 +6,13 @@ package bots
import (
"code.gitea.io/gitea/modules/web"
"gitea.com/gitea/proto/gen/proto/v1/v1connect"
"github.com/bufbuild/connect-go"
grpchealth "github.com/bufbuild/connect-grpchealth-go"
grpcreflect "github.com/bufbuild/connect-grpcreflect-go"
)
func Routes(r *web.Route) {
compress1KB := connect.WithCompressMinBytes(1024)
service := &RunnerService{}
path, handler := v1connect.NewBuildServiceHandler(
service,
compress1KB,
)
// grpcV1
grpcPath, gHandler := grpcreflect.NewHandlerV1(
grpcreflect.NewStaticReflector(v1connect.BuildServiceName),
compress1KB,
)
// grpcV1Alpha
grpcAlphaPath, gAlphaHandler := grpcreflect.NewHandlerV1Alpha(
grpcreflect.NewStaticReflector(v1connect.BuildServiceName),
compress1KB,
)
// grpcHealthCheck
grpcHealthPath, gHealthHandler := grpchealth.NewHandler(
grpchealth.NewStaticChecker(v1connect.BuildServiceName),
compress1KB,
)
// socket connection
r.Get("/socket", socketServe)
// restful connection
r.Post(path+"{name}", giteaHandler(handler))
// grpc connection
r.Post(grpcPath+"{name}", giteaHandler(gHandler))
r.Post(grpcAlphaPath+"{name}", giteaHandler(gAlphaHandler))
// healthy check connection
r.Post(grpcHealthPath+"{name}", giteaHandler(gHealthHandler))
// runner service
runnerServiceRoute(r)
// ping service
pingServiceRoute(r)
}