mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 12:55:23 +02:00
chore: update grpc router path
This commit is contained in:
parent
48f5c152b9
commit
e346581344
@ -5,31 +5,26 @@
|
||||
package bots
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/bots/grpc"
|
||||
)
|
||||
|
||||
func grpcHandler(h http.Handler) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
log.Trace("protocol version: %v", r.Proto)
|
||||
h.ServeHTTP(w, r)
|
||||
func Routes(_ context.Context, prefix string) *web.Route {
|
||||
m := web.NewRoute()
|
||||
|
||||
for _, fn := range []grpc.RouteFn{
|
||||
grpc.V1Route,
|
||||
grpc.V1AlphaRoute,
|
||||
grpc.HealthRoute,
|
||||
grpc.PingRoute,
|
||||
grpc.RunnerRoute,
|
||||
} {
|
||||
path, handler := fn()
|
||||
m.Post(path+"*", http.StripPrefix(prefix, handler).ServeHTTP)
|
||||
}
|
||||
}
|
||||
|
||||
func gRPCRouter(r *web.Route, fn grpc.RouteFn) {
|
||||
p, h := fn()
|
||||
r.Post(p+"{name}", grpcHandler(h))
|
||||
}
|
||||
|
||||
func Routes(r *web.Route) *web.Route {
|
||||
gRPCRouter(r, grpc.V1Route)
|
||||
gRPCRouter(r, grpc.V1AlphaRoute)
|
||||
gRPCRouter(r, grpc.HealthRoute)
|
||||
gRPCRouter(r, grpc.PingRoute)
|
||||
gRPCRouter(r, grpc.RunnerRoute)
|
||||
|
||||
return r
|
||||
return m
|
||||
}
|
||||
|
@ -5,12 +5,12 @@
|
||||
package bots
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/routers/api/bots/ping"
|
||||
)
|
||||
|
||||
func TestPingService(t *testing.T) {
|
||||
ping.MainServiceTest(t, Routes(web.NewRoute()))
|
||||
ping.MainServiceTest(t, Routes(context.Background(), ""))
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"code.gitea.io/bots-proto-go/ping/v1/pingv1connect"
|
||||
"github.com/bufbuild/connect-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func MainServiceTest(t *testing.T, h http.Handler) {
|
||||
@ -46,7 +47,7 @@ func MainServiceTest(t *testing.T, h http.Handler) {
|
||||
result, err := client.Ping(context.Background(), connect.NewRequest(&pingv1.PingRequest{
|
||||
Data: "foobar",
|
||||
}))
|
||||
assert.NoError(t, err)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Hello, foobar!", result.Msg.Data)
|
||||
}
|
||||
})
|
||||
|
@ -202,6 +202,11 @@ func NormalRoutes(ctx context.Context) *web.Route {
|
||||
// This implements the OCI API (Note this is not preceded by /api but is instead /v2)
|
||||
r.Mount("/v2", packages_router.ContainerRoutes(ctx))
|
||||
}
|
||||
_ = bots_router.Routes(r)
|
||||
|
||||
if setting.Bots.Enabled {
|
||||
prefix := "/api/bots"
|
||||
r.Mount(prefix, bots_router.Routes(ctx, prefix))
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user