Redoc Theme for gRPC UI
Go >= 1.21
go get github.com/nhatthm/grpcui-redoc
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))
}
If this project help you reduce time to develop, you can give me a cup of coffee :)
or scan this