8996b9b0e4
We use [connect-go](https://github.com/bufbuild/connect-go) instead of [grpc-go](https://github.com/grpc/grpc-go) because connect-go support HTTP/1.1, that means we can mount the gRPC api on the Gitea server without change the protocol.
So it doesn't make sense that make the runner support both HTTP/1.1 and HTTP/2, and [upgrade the protocol used on Gitea](
ae018b6b48/modules/graceful/server_http.go (L23)
) to support HTTP/2 and h2c. Although it works right now, I believe there'll be lots of problems when the Gitea server is behind a reverse proxy.
So let's KISS, we don't touch the http protocol of Gitea, and disable HTTP/2 for runner. And we would support HTTP/2 in the future if we really need it.
Co-authored-by: Jason Song <i@wolfogre.com>
Reviewed-on: https://gitea.com/gitea/act_runner/pulls/4
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package client
|
|
|
|
import (
|
|
"code.gitea.io/bots-proto-go/ping/v1/pingv1connect"
|
|
"code.gitea.io/bots-proto-go/runner/v1/runnerv1connect"
|
|
"context"
|
|
"gitea.com/gitea/act_runner/core"
|
|
"github.com/bufbuild/connect-go"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// New returns a new runner client.
|
|
func New(endpoint string, uuid, token string, opts ...connect.ClientOption) *HTTPClient {
|
|
baseURL := strings.TrimRight(endpoint, "/") + "/api/bots"
|
|
|
|
opts = append(opts, connect.WithInterceptors(connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
|
|
return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
|
|
if uuid != "" {
|
|
req.Header().Set(core.UUIDHeader, uuid)
|
|
}
|
|
if token != "" {
|
|
req.Header().Set(core.TokenHeader, token)
|
|
}
|
|
return next(ctx, req)
|
|
}
|
|
})))
|
|
|
|
return &HTTPClient{
|
|
PingServiceClient: pingv1connect.NewPingServiceClient(
|
|
http.DefaultClient,
|
|
baseURL,
|
|
opts...,
|
|
),
|
|
RunnerServiceClient: runnerv1connect.NewRunnerServiceClient(
|
|
http.DefaultClient,
|
|
baseURL,
|
|
opts...,
|
|
),
|
|
endpoint: endpoint,
|
|
}
|
|
}
|
|
|
|
func (c *HTTPClient) Address() string {
|
|
return c.endpoint
|
|
}
|
|
|
|
var _ Client = (*HTTPClient)(nil)
|
|
|
|
// An HTTPClient manages communication with the runner API.
|
|
type HTTPClient struct {
|
|
pingv1connect.PingServiceClient
|
|
runnerv1connect.RunnerServiceClient
|
|
endpoint string
|
|
}
|