chore(proto): update import path

Signed-off-by: GiteaBot <teabot@gitea.io>
This commit is contained in:
GiteaBot
2022-08-17 15:01:10 +08:00
committed by Jason Song
parent b84aa84a0f
commit 257ba77e8d
4 changed files with 627 additions and 30 deletions

View File

@@ -7,11 +7,11 @@ package bots
import (
"context"
"fmt"
"log"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/web"
v1 "gitea.com/gitea/proto/gen/proto/v1"
"gitea.com/gitea/proto/gen/proto/v1/v1connect"
pingv1 "gitea.com/gitea/proto-go/ping/v1"
"gitea.com/gitea/proto-go/ping/v1/pingv1connect"
"github.com/bufbuild/connect-go"
grpchealth "github.com/bufbuild/connect-grpchealth-go"
@@ -22,11 +22,12 @@ type PingService struct{}
func (s *PingService) Ping(
ctx context.Context,
req *connect.Request[v1.PingRequest],
) (*connect.Response[v1.PingResponse], error) {
log.Println("Content-Type: ", req.Header().Get("Content-Type"))
log.Println("User-Agent: ", req.Header().Get("User-Agent"))
res := connect.NewResponse(&v1.PingResponse{
req *connect.Request[pingv1.PingRequest],
) (*connect.Response[pingv1.PingResponse], error) {
log.Info("Content-Type: %s", req.Header().Get("Content-Type"))
log.Info("User-Agent: %s", req.Header().Get("User-Agent"))
log.Info("X-Gitea-Token: %s", req.Header().Get("X-Gitea-Token"))
res := connect.NewResponse(&pingv1.PingResponse{
Data: fmt.Sprintf("Hello, %s!", req.Msg.Data),
})
res.Header().Set("Gitea-Version", "v1")
@@ -37,26 +38,26 @@ func pingServiceRoute(r *web.Route) {
compress1KB := connect.WithCompressMinBytes(1024)
pingService := &PingService{}
connectPath, connecthandler := v1connect.NewPingServiceHandler(
connectPath, connecthandler := pingv1connect.NewPingServiceHandler(
pingService,
compress1KB,
)
// grpcV1
grpcPath, gHandler := grpcreflect.NewHandlerV1(
grpcreflect.NewStaticReflector(v1connect.PingServiceName),
grpcreflect.NewStaticReflector(pingv1connect.PingServiceName),
compress1KB,
)
// grpcV1Alpha
grpcAlphaPath, gAlphaHandler := grpcreflect.NewHandlerV1Alpha(
grpcreflect.NewStaticReflector(v1connect.PingServiceName),
grpcreflect.NewStaticReflector(pingv1connect.PingServiceName),
compress1KB,
)
// grpcHealthCheck
grpcHealthPath, gHealthHandler := grpchealth.NewHandler(
grpchealth.NewStaticChecker(v1connect.PingServiceName),
grpchealth.NewStaticChecker(pingv1connect.PingServiceName),
compress1KB,
)

View File

@@ -9,8 +9,8 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/web"
v1 "gitea.com/gitea/proto/gen/proto/v1"
"gitea.com/gitea/proto/gen/proto/v1/v1connect"
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
"gitea.com/gitea/proto-go/runner/v1/runnerv1connect"
"github.com/bufbuild/connect-go"
grpchealth "github.com/bufbuild/connect-grpchealth-go"
@@ -21,25 +21,28 @@ type RunnerService struct{}
func (s *RunnerService) Connect(
ctx context.Context,
req *connect.Request[v1.ConnectRequest],
) (*connect.Response[v1.ConnectResponse], error) {
req *connect.Request[runnerv1.ConnectRequest],
) (*connect.Response[runnerv1.ConnectResponse], error) {
log.Info("Request headers: %v", req.Header())
res := connect.NewResponse(&v1.ConnectResponse{
JobId: 100,
res := connect.NewResponse(&runnerv1.ConnectResponse{
Stage: &runnerv1.Stage{
RunnerUuid: "foobar",
BuildUuid: "foobar",
},
})
res.Header().Set("Gitea-Version", "v1")
res.Header().Set("Gitea-Version", "runnerv1")
return res, nil
}
func (s *RunnerService) Accept(
ctx context.Context,
req *connect.Request[v1.AcceptRequest],
) (*connect.Response[v1.AcceptResponse], error) {
req *connect.Request[runnerv1.AcceptRequest],
) (*connect.Response[runnerv1.AcceptResponse], error) {
log.Info("Request headers: %v", req.Header())
res := connect.NewResponse(&v1.AcceptResponse{
res := connect.NewResponse(&runnerv1.AcceptResponse{
JobId: 100,
})
res.Header().Set("Gitea-Version", "v1")
res.Header().Set("Gitea-Version", "runnerv1")
return res, nil
}
@@ -47,26 +50,26 @@ func runnerServiceRoute(r *web.Route) {
compress1KB := connect.WithCompressMinBytes(1024)
runnerService := &RunnerService{}
connectPath, connecthandler := v1connect.NewRunnerServiceHandler(
connectPath, connecthandler := runnerv1connect.NewRunnerServiceHandler(
runnerService,
compress1KB,
)
// grpcV1
grpcPath, gHandler := grpcreflect.NewHandlerV1(
grpcreflect.NewStaticReflector(v1connect.RunnerServiceName),
grpcreflect.NewStaticReflector(runnerv1connect.RunnerServiceName),
compress1KB,
)
// grpcV1Alpha
grpcAlphaPath, gAlphaHandler := grpcreflect.NewHandlerV1Alpha(
grpcreflect.NewStaticReflector(v1connect.RunnerServiceName),
grpcreflect.NewStaticReflector(runnerv1connect.RunnerServiceName),
compress1KB,
)
// grpcHealthCheck
grpcHealthPath, gHealthHandler := grpchealth.NewHandler(
grpchealth.NewStaticChecker(v1connect.RunnerServiceName),
grpchealth.NewStaticChecker(runnerv1connect.RunnerServiceName),
compress1KB,
)