mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
758714ed6d
These were changes I drafted when reviewing 7c731e02a9
,
and had these stashed in my local git;
- rename receiver to prevent "unconsistent receiver name" warnings
- make NewRouter() slightly more idiomatic, and wrap the options,
to make them easier to read.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
41 lines
989 B
Go
41 lines
989 B
Go
package grpc // import "github.com/docker/docker/api/server/router/grpc"
|
|
|
|
import (
|
|
"github.com/docker/docker/api/server/router"
|
|
"github.com/moby/buildkit/util/grpcerrors"
|
|
"golang.org/x/net/http2"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type grpcRouter struct {
|
|
routes []router.Route
|
|
grpcServer *grpc.Server
|
|
h2Server *http2.Server
|
|
}
|
|
|
|
// NewRouter initializes a new grpc http router
|
|
func NewRouter(backends ...Backend) router.Router {
|
|
r := &grpcRouter{
|
|
h2Server: &http2.Server{},
|
|
grpcServer: grpc.NewServer(
|
|
grpc.UnaryInterceptor(grpcerrors.UnaryServerInterceptor),
|
|
grpc.StreamInterceptor(grpcerrors.StreamServerInterceptor),
|
|
),
|
|
}
|
|
for _, b := range backends {
|
|
b.RegisterGRPC(r.grpcServer)
|
|
}
|
|
r.initRoutes()
|
|
return r
|
|
}
|
|
|
|
// Routes returns the available routers to the session controller
|
|
func (gr *grpcRouter) Routes() []router.Route {
|
|
return gr.routes
|
|
}
|
|
|
|
func (gr *grpcRouter) initRoutes() {
|
|
gr.routes = []router.Route{
|
|
router.NewPostRoute("/grpc", gr.serveGRPC),
|
|
}
|
|
}
|