Coder Social home page Coder Social logo

grpcui-redoc's Introduction

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

grpcui-redoc's People

Contributors

dependabot[bot] avatar nhatthm avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.