grpcuiredoc

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 9 Imported by: 0

README

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.21

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

Documentation

Overview

Package grpcuiredoc provides Redoc theme for grpcui.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(ch grpcdynamic.Channel, target string, methods []*desc.MethodDescriptor, files []*desc.FileDescriptor, opts ...HandlerOption) http.Handler

Handler is a wrapper around github.com/fullstorydev/grpcui/standalone.Handler to provide the theme.

func HandlerViaReflection

func HandlerViaReflection(ctx context.Context, cc grpc.ClientConnInterface, target string, opts ...HandlerOption) (http.Handler, error)

HandlerViaReflection is a wrapper around github.com/fullstorydev/grpcui/standalone.HandlerViaReflection to provide the theme.

Types

type HandlerOption added in v0.2.0

type HandlerOption = standalone.HandlerOption

HandlerOption is an alias of github.com/fullstorydev/grpcui/standalone.HandlerOption to avoid multiple imports.

func AddDescription

func AddDescription(desc string) HandlerOption

AddDescription adds description after the target section in the header.

Jump to

Keyboard shortcuts

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