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

Proto 生成 Go 代码支持 repeated 字段 #1193

Closed
ringsaturn opened this issue Jul 15, 2021 · 4 comments
Closed

Proto 生成 Go 代码支持 repeated 字段 #1193

ringsaturn opened this issue Jul 15, 2021 · 4 comments
Labels
Milestone

Comments

@ringsaturn
Copy link

ringsaturn commented Jul 15, 2021

What happened:

Kratos 生成的 Go 代码和 grpc-gateway 不一致

What you expected to happen:

之前在 #1192 提过支持 URL 参数含有 , 分割的多个参数,后来发现 grpc-gateway 已经支持了 grpc-ecosystem/grpc-gateway#742

写了个简单的 demo 在这里 ringsaturn/grpc-gateway-demo@3e31c7f 是能正常生成 Go 代码并用 runtime.Float32Slice(val, ",") 解析参数

func request_Greeter_GetName_0(ctx context.Context, marshaler runtime.Marshaler, client GreeterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq GetRequest
	var metadata runtime.ServerMetadata

	var (
		val string
		ok  bool
		err error
		_   = err
	)

	val, ok = pathParams["coordinates"]
	if !ok {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "coordinates")
	}

	protoReq.Coordinates, err = runtime.Float32Slice(val, ",")
	if err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "coordinates", err)
	}

	msg, err := client.GetName(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

但是 Kratos 生成的代码没有用这个方法解析参数 ringsaturn/kratos-demo@dfcbb4e

How to reproduce it (as minimally and precisely as possible):

两个 demo 仓库都放在 GitHub 了

Anything else we need to know?:

Environment:

  • Kratos version (use kratos -v): kratos version v2.0.0
  • Go version (use go version): go version go1.14 darwin/amd64
  • OS (e.g: cat /etc/os-release): macOS 11.4
  • Others:
@ringsaturn ringsaturn added the bug Something isn't working label Jul 15, 2021
@shenqidebaozi
Copy link
Member

@longXboy 虾哥帮忙看下吧

@longXboy
Copy link
Member

是说要支持repeated字段吗?

@ringsaturn
Copy link
Author

是说要支持repeated字段吗?

@longXboy
Copy link
Member

是说要支持repeated字段吗?

好,我们评估一下支持的复杂度

@longXboy longXboy added this to the v2.2.0 milestone Jul 15, 2021
@longXboy longXboy added feature and removed bug Something isn't working labels Jul 15, 2021
@ringsaturn ringsaturn changed the title Kratos 从 Proto 生成的 Go 代码和 grpc-gateway 不一致 Proto 生成 Go 代码支持 repeated 字段 Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants