chore(router): Add grpc and grep-web api

Using connect-go package

https://github.com/bufbuild/connect-go

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2022-08-13 11:48:14 +08:00
committed by Jason Song
parent 92d15afd18
commit 0e79fc556a
6 changed files with 303 additions and 203 deletions

View File

@ -0,0 +1,48 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bots
import (
"context"
"net/http"
"code.gitea.io/gitea/modules/log"
v1 "gitea.com/gitea/proto/gen/proto/v1"
"github.com/bufbuild/connect-go"
)
type RunnerService struct{}
func (s *RunnerService) Connect(
ctx context.Context,
req *connect.Request[v1.ConnectRequest],
) (*connect.Response[v1.ConnectResponse], error) {
log.Info("Request headers: %v", req.Header())
res := connect.NewResponse(&v1.ConnectResponse{
JobId: 100,
})
res.Header().Set("Gitea-Version", "v1")
return res, nil
}
func (s *RunnerService) Accept(
ctx context.Context,
req *connect.Request[v1.AcceptRequest],
) (*connect.Response[v1.AcceptResponse], error) {
log.Info("Request headers: %v", req.Header())
res := connect.NewResponse(&v1.AcceptResponse{
JobId: 100,
})
res.Header().Set("Gitea-Version", "v1")
return res, nil
}
func giteaHandler(h http.Handler) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Info("Got connection: %v", r.Proto)
h.ServeHTTP(w, r)
})
}