grpc

package
v14.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

README

gRPC

This middleware serves gRPC and Iris on one port, typically 443. It routes a request to your gRPC server when the request looks like gRPC, and to the Iris router otherwise. Both the server and its clients must run HTTP/2.

Installation

To use the gRPC middleware, you need to import it in your project:

import grpcWrapper "github.com/kataras/iris/v14/middleware/grpc"
API
func New(grpcServer http.Handler) iris.Handler

The New function returns a new gRPC Iris router wrapper for a gRPC server. It takes an http.Handler as an argument, which should be your gRPC server.

Parameters
  • grpcServer (http.Handler): The gRPC server handler.
Returns
  • iris.Handler: The Iris request context handler.
Example

Here is a complete example demonstrating how to use the gRPC middleware with an Iris application:

package main

import (
	"context"
	"log"
	"net"

	"github.com/kataras/iris/v14"
	grpcWrapper "github.com/kataras/iris/v14/middleware/grpc"

	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials"
	"google.golang.org/grpc/credentials/insecure"
)

// Define your gRPC service
type greeterServer struct{}

func (s *greeterServer) SayHello(ctx context.Context, req *HelloRequest) (*HelloReply, error) {
	return &HelloReply{Message: "Hello " + req.Name}, nil
}

func main() {
	app := iris.New()

	// Create a new gRPC server
	grpcServer := grpc.NewServer()

	// Register your gRPC service
	RegisterGreeterServer(grpcServer, &greeterServer{})

	// Use the gRPC middleware
	app.UseRouter(grpcWrapper.New(grpcServer))

	// Serve both gRPC and HTTP on the same port
	app.Run(iris.ServerOptions{Addr: ":443", CertFile: "server.crt", KeyFile: "server.key"})
}
Notes
  • The Iris server and its clients must run HTTP/2.
  • You can register more than one gRPC service on the same gRPC server.

Documentation

Overview

Package grpc serves a gRPC (or gRPC-Web) server through an Iris route.

Its entry point is New(grpcServer http.Handler), which returns a Handler. The single input is the server itself, so it is a plain argument and there is no Options struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(grpcServer http.Handler) context.Handler

New returns a new gRPC Iris router wrapper for a gRPC server. useful when you want to share one port (such as 443 for https) between gRPC and Iris.

The Iris server SHOULD run under HTTP/2 and clients too.

Usage:

import grpcWrapper "github.com/kataras/iris/v14/middleware/grpc"
[...]
app := iris.New()
grpcServer := grpc.NewServer()
app.UseRouter(grpcWrapper.New(grpcServer))

Types

This section is empty.

Jump to

Keyboard shortcuts

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