Help us shape the future of Go! Take the 2026 Go Developer Survey

gcprest

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 30 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPStatus

func HTTPStatus(c codes.Code) int

HTTPStatus maps a gRPC code to the HTTP status Google APIs use for it.

func Serve

func Serve(srv *grpc.Server, l net.Listener) error

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

func ServeWithFallback(srv *grpc.Server, l net.Listener, fallback http.Handler) error

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.

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.

func New

func New(srv *grpc.Server, conn *grpc.ClientConn) *Server

New indexes every annotated unary and server-streaming method registered on srv and returns a Server that calls them over conn.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the REST-only HTTP handler.

Directories

Path Synopsis
Package resttest drives raw REST/JSON request flows against a gcprest-served emulator.
Package resttest drives raw REST/JSON request flows against a gcprest-served emulator.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL