mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 21:05:18 +02:00
chore: update grpc router path
This commit is contained in:
parent
48f5c152b9
commit
e346581344
@ -5,31 +5,26 @@
|
|||||||
package bots
|
package bots
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
|
||||||
"code.gitea.io/gitea/modules/web"
|
"code.gitea.io/gitea/modules/web"
|
||||||
"code.gitea.io/gitea/routers/api/bots/grpc"
|
"code.gitea.io/gitea/routers/api/bots/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func grpcHandler(h http.Handler) http.HandlerFunc {
|
func Routes(_ context.Context, prefix string) *web.Route {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
m := web.NewRoute()
|
||||||
log.Trace("protocol version: %v", r.Proto)
|
|
||||||
h.ServeHTTP(w, r)
|
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) {
|
return m
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
package bots
|
package bots
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/web"
|
|
||||||
"code.gitea.io/gitea/routers/api/bots/ping"
|
"code.gitea.io/gitea/routers/api/bots/ping"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPingService(t *testing.T) {
|
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"
|
"code.gitea.io/bots-proto-go/ping/v1/pingv1connect"
|
||||||
"github.com/bufbuild/connect-go"
|
"github.com/bufbuild/connect-go"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MainServiceTest(t *testing.T, h http.Handler) {
|
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{
|
result, err := client.Ping(context.Background(), connect.NewRequest(&pingv1.PingRequest{
|
||||||
Data: "foobar",
|
Data: "foobar",
|
||||||
}))
|
}))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "Hello, foobar!", result.Msg.Data)
|
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)
|
// This implements the OCI API (Note this is not preceded by /api but is instead /v2)
|
||||||
r.Mount("/v2", packages_router.ContainerRoutes(ctx))
|
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
|
return r
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user