1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

first release of SSO package and more examples

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-03-28 14:00:26 +03:00
parent 45d693850b
commit cf36063adf
33 changed files with 1805 additions and 67 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"context"
"log"
pb "github.com/kataras/iris/v12/_examples/mvc/grpc-compatible/helloworld"
@@ -47,17 +48,32 @@ func newApp() *iris.Application {
// Register MVC application controller for gRPC services.
// You can bind as many mvc gRpc services in the same Party or app,
// as the ServiceName differs.
mvc.New(app).Handle(ctrl, mvc.GRPC{
Server: grpcServer, // Required.
ServiceName: "helloworld.Greeter", // Required.
Strict: false,
})
mvc.New(app).
Register(new(myService)).
Handle(ctrl, mvc.GRPC{
Server: grpcServer, // Required.
ServiceName: "helloworld.Greeter", // Required.
Strict: false,
})
return app
}
type service interface {
DoSomething() error
}
type myService struct{}
func (s *myService) DoSomething() error {
log.Println("service: DoSomething")
return nil
}
type myController struct {
// Ctx iris.Context
SingletonDependency service
}
// SayHello implements helloworld.GreeterServer.
@@ -70,5 +86,10 @@ type myController struct {
// @Success 200 {string} string "Hello {name}"
// @Router /helloworld.Greeter/SayHello [post]
func (c *myController) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
err := c.SingletonDependency.DoSomething()
if err != nil {
return nil, err
}
return &pb.HelloReply{Message: "Hello " + in.GetName()}, nil
}