mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 18:37:05 +00:00
fix #1665
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
pb "grpcexample/helloworld"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/mvc"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type Greeter struct {
|
||||
pb.UnimplementedGreeterBidirectionalStreamServer
|
||||
}
|
||||
|
||||
// SayHello implements the proto Bidirectional Stream Greeter service.
|
||||
func (g *Greeter) SayHello(stream pb.GreeterBidirectionalStream_SayHelloServer) error {
|
||||
for {
|
||||
in, err := stream.Recv()
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
println("Received input: " + in.Name)
|
||||
// On client side you can implement the 'read' operation too.
|
||||
stream.Send(&pb.HelloReply{Message: "Hello " + in.Name})
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
grpcServer := grpc.NewServer()
|
||||
|
||||
myService := &Greeter{}
|
||||
pb.RegisterGreeterBidirectionalStreamServer(grpcServer, myService)
|
||||
|
||||
rootApp := mvc.New(app)
|
||||
rootApp.Handle(myService, mvc.GRPC{
|
||||
Server: grpcServer, // Required.
|
||||
ServiceName: "helloworld.GreeterBidirectionalStream", // Required.
|
||||
Strict: true, // Set it to true on gRPC streaming.
|
||||
})
|
||||
|
||||
app.Run(iris.TLS(":443", "../server.crt", "../server.key"))
|
||||
}
|
||||
Reference in New Issue
Block a user