/grpcui-redoc

Redoc Theme for gRPC UI

Primary LanguageCSSMIT LicenseMIT

Redoc Theme for gRPC UI

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

Redoc Theme for gRPC UI

Don't gRPC without it!

Prerequisites

  • Go >= 1.17

Install

go get github.com/nhatthm/grpcui-redoc

Usage

Use grpcuiredoc.HandlerViaReflection() or grpcuiredoc.Handler() the same way as fullstorydev/grpcui.

For example:

package exmaple

import (
	"fmt"
	"net/http"
	"os"
	"path/filepath"

	grpcuiredoc "github.com/nhatthm/grpcui-redoc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

func main() {
	// ----------------------------
	// Start up our gRPC server
	// ----------------------------
	svr := grpc.NewServer()

	// we need the reflection service, to power the UI
	reflection.Register(svr)

	// ...
	// register our gRPC services and then start up the server in a goroutine
	// ...

	// ----------------------------
	// Create a client to local server
	// ----------------------------
	cc, err := grpc.Dial(fmt.Sprintf("127.0.0.1:%d", grpcPort))
	if err != nil {
		panic(fmt.Errorf("failed to create client to local server: %w", err))
	}

	// ----------------------------
	// Create gRPCui handler
	// ----------------------------
	target := fmt.Sprintf("%s:%d", filepath.Base(os.Args[0]), grpcPort)
	// This one line of code is all that is needed to create the UI handler!
	h, err := grpcuiredoc.HandlerViaReflection(ctx, cc, target)
	if err != nil {
		panic(fmt.Errorf("failed to create client to local server: %w", err))
	}

	// ----------------------------
	// Now wire it up to an HTTP server
	// ----------------------------
	serveMux := http.NewServeMux()

	serveMux.Handle("/grpcui/", http.StripPrefix("/grpcui", h))
}

image

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

Paypal donation

paypal

       or scan this