Documentation
¶
Overview ¶
Package gcprest serves the REST/JSON surface of a gRPC-only Google Cloud emulator by transcoding HTTP requests, driven by the google.api.http annotations on the service protos, into in-process calls on the registered gRPC implementation.
Index ¶
- func HTTPStatus(c codes.Code) int
- func Serve(srv *grpc.Server, l net.Listener) error
- func ServeWithExtras(srv *grpc.Server, l net.Listener, fallback http.Handler, extras ...Extra) error
- func ServeWithFallback(srv *grpc.Server, l net.Listener, fallback http.Handler) error
- func WriteError(w http.ResponseWriter, err error)
- type Extra
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPStatus ¶
HTTPStatus maps a gRPC code to the HTTP status Google APIs use for it.
func Serve ¶
Serve serves srv's gRPC API and its REST/JSON transcoding on l, telling them apart by the HTTP/2 connection preface. REST calls reach the handlers through an in-memory pipe, never the network. Stopping srv closes l and the REST server with it.
func ServeWithExtras ¶
func ServeWithExtras(srv *grpc.Server, l net.Listener, fallback http.Handler, extras ...Extra) error
ServeWithExtras is ServeWithFallback with additional path-matched HTTP handlers.
func ServeWithFallback ¶
ServeWithFallback is Serve with one extra HTTP handler: requests under /v2 (the Docker Registry API) go to fallback instead of the REST transcoder. A nil fallback behaves like Serve.
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
WriteError writes err as the Google JSON error envelope, with its status details.
Types ¶
type Extra ¶
type Extra struct {
Match func(path string) bool
MatchRequest func(r *http.Request) bool
Handler http.Handler
}
Extra routes requests to Handler instead of the REST transcoder. MatchRequest, when set, sees the whole request (Host included) and takes precedence; otherwise Match decides on the URL path alone.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds the REST routes derived from a gRPC server's registered services.