Skip to content

[FEATURE] When using iris and gRPC, if a struct contains a parent struct, the parent struct will be handled and parsed. #2103

@AliangCoder

Description

@AliangCoder

Describe the bug
When using iris and gRPC, if a struct contains a parent struct, the parent struct will be handled and parsed.
To Reproduce
Steps to reproduce the behavior:

type myController struct {
	// Ctx iris.Context
	BaseController
	SingletonDependency service
}

When I use it

ctrl := &myController{}
// Register gRPC server.
grpcServer := grpc.NewServer()
pb.RegisterGreeterServer(grpcServer, ctrl)
mvc.New(app).
	Register(new(myService)).
	Handle(ctrl, mvc.GRPC{
		Server:      grpcServer,           // Required.
		ServiceName: "helloworld.Greeter", // Required.
		Strict:      false,
	})

BaseController

package main

import (
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"
)

type BaseController struct {
	Ctx iris.Context
}

func (c *BaseController) ReadJSON(i interface{}) error {

	return nil
}

func (c *BaseController) MessageResp(success bool, message string) *mvc.Response {

	return nil
}

func (c *BaseController) ErrParamsResp() *mvc.Response {

	return nil
}

stdout

POST: /helloworld.Greeter/ErrParamsResp gRPC myController (./mvc/grpc.go:46)
      • myController.ErrParamsResp (./_examples/mvc/grpc-compatible/base.go:22)
POST: /helloworld.Greeter/MessageResp gRPC myController (./mvc/grpc.go:46)
      • myController.MessageResp (./_examples/mvc/grpc-compatible/base.go:17)
POST: /helloworld.Greeter/ReadJSON gRPC myController (./mvc/grpc.go:46)
      • myController.ReadJSON (./_examples/mvc/grpc-compatible/base.go:12)
POST: /helloworld.Greeter/SayHello gRPC myController (./mvc/grpc.go:46)
      • myController.SayHello (./_examples/mvc/grpc-compatible/main.go:89)

Expected behavior
A clear and concise description of what you expected to happen.
stdout should be

POST: /helloworld.Greeter/SayHello gRPC myController (./mvc/grpc.go:46)
      • myController.SayHello (./_examples/mvc/grpc-compatible/main.go:89)

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: mac m1
    iris.Version
  • v12.2.0

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions