Documentation ¶
Overview ¶
Package standalone provides a stand-alone HTTP handler that provides a complete gRPC web UI that includes both the web page and relevant server-side handlers. The web page includes HTML, CSS, and JS sources, which can be customized only regarding the "target" in the page header (which is intended to show the server to which RPC requests are directed). The actual list of methods exposed via the form is also customizable.
This is the same web content that the `grpcui` command-line program exposes. It starts up a web server that includes only this stand-alone handler. If you need more control over the page in which the UI form gets embedded or over the CSS/styling of the page, instead use the various functions in the "github.com/fullstorydev/grpcui" package to assemble your own web UI.
Note that this package bundles the JS dependencies of the web form. It provides jQuery 3.3.1 and jQuery-UI 1.12.1.
An example of using the package with a server supporting reflection:
cc, err := grpc.DialContext(ctx, "dns:///my-grpc-server:8080", grpc.WithBlock()) if err != nil { return err } h, err := standalone.HandlerViaReflection(ctx, cc, "dns:///my-grpc-server:8080") if err != nil { return err } http.ListenAndServe(":8080", h)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(c Config, ch grpcdynamic.Channel, target string, methods []*desc.MethodDescriptor, files []*desc.FileDescriptor) http.Handler
Handler returns an HTTP handler that provides a fully-functional gRPC web UI, including the main index (with the HTML form), all needed CSS and JS assets, and the handlers that provide schema metadata and perform RPC invocations.
All RPC invocations are sent to the given channel. The given target is shown in the header of the web UI, to show the user where their requests are being sent. The given methods enumerate all supported RPC methods, and the given files enumerate all known protobuf (for enumerating all supported message types, to support the use of google.protobuf.Any messages).
The returned handler expects to serve resources from "/". If it will instead be handling a sub-path (e.g. handling "/rpc-ui/") then use http.StripPrefix.
func HandlerViaReflection ¶
func HandlerViaReflection(ctx context.Context, c Config, cc *grpc.ClientConn, target string) (http.Handler, error)
HandlerViaReflection tries to query the provided connection for all services and methods supported by the server, and constructs a handler to serve the UI.
The handler has the same properties as the one returned by Handler.