Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] MVC does not support receiving protobufs #2489

Open
dongzhanhub opened this issue Sep 10, 2024 · 5 comments
Open

[BUG] MVC does not support receiving protobufs #2489

dongzhanhub opened this issue Sep 10, 2024 · 5 comments
Assignees

Comments

@dongzhanhub
Copy link

dongzhanhub commented Sep 10, 2024

Describe the bug
On the issue of receiving protobuf data exception in MVC
To Reproduce

  1. The following is the main code segment, which works as a whole except for errors when receiving protobuf
  app := iris.New()
  return app.Run(iris.Addr(":"+port),
   	iris.WithKeepAlive(1*time.Minute),
   	iris.WithoutInterruptHandler,
   	iris.WithOptimizations,
   	iris.WithProtoJSON,
   	iris.WithoutBodyConsumptionOnUnmarshal,
   	iris.WithoutServerError(iris.ErrServerClosed),
   	iris.WithRemoteAddrHeader("X-Real-IP"),
   )
   
   mvcApp := mvc.New(app)

   api := mvcApp.Party("/")
   api.Party("test").Handle(new(controllers.TestController))

Question:Directly in the outermost layer directly error, the program has not been executed to the controller
Response Error:valid character '$' looking for beginning of valueinvalid character '$' looking for beginning of value

  1. This code reads protobuf without problem:
app.Post("/read", read)

func read(ctx iris.Context) {
	var request pb.FcmRequest

	err := ctx.ReadProtobuf(&request)
	if err != nil {
		ctx.StopWithError(iris.StatusBadRequest, err)
		return
	}

	fmt.Println(request)
}


func read(ctx iris.Context) {
	var request pb.FcmRequest

	err := ctx.ReadProtobuf(&request)
	if err != nil {
		ctx.StopWithError(iris.StatusBadRequest, err)
		return
	}

	fmt.Println(request)

	ctx.Writef("HelloRequest.Name = %s", request)
}

@Dexus
Copy link

Dexus commented Sep 10, 2024

@dongzhanhub please use the code blocks to show the code in good format. Thanks

@dongzhanhub
Copy link
Author

dongzhanhub commented Sep 10, 2024

@dongzhanhub please use the code blocks to show the code in good format. Thanks
Sorry, didn't notice, formatted
But I have a question, how does MVC support receiving protobuf?

@Dexus
Copy link

Dexus commented Sep 10, 2024

For the protobuf with mvc check the grpc examples with mvc

@dongzhanhub
Copy link
Author

dongzhanhub commented Sep 10, 2024

For the protobuf with mvc check the grpc examples with mvc

Thanks for your reply. I have seen this example about rpc, the configuration of pb.proto must be based on rpc service mode to receive protobuf data, which is difficult to coordinate multiple parties to change this configuration. Is MVC not currently supported in the form of a normal api? Or is there currently a way to receive octet-stream?
this example:https://github.com/kataras/iris/blob/main/_examples/mvc/grpc-compatible/main.go

@Dexus
Copy link

Dexus commented Sep 16, 2024

you can send both json or pb directly in the body. Both works for me.

the only thing you need is the DI ob the protobuf in the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants