Google Cloud Endpoints(ESP)gRPC转码为驼峰式保护套 [英] Google Cloud Endpoints (ESP) gRPC transcoding to camel case

本文介绍了Google Cloud Endpoints(ESP)gRPC转码为驼峰式保护套的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照此处的说明使用Google Cloud Endpoints/ESP部署了gRPC服务器:

I have deployed a gRPC server using Google Cloud Endpoints / ESP, following the instructions here:

https://cloud.google.com/endpoints /docs/grpc/get-started-kubernetes-engine

在我的原型文件中,按照协议缓冲区命名约定(

In my proto file, my fields are named in snake_case, following the Protocol Buffers naming conventions (https://developers.google.com/protocol-buffers/docs/style#message-and-field-names), as below:

message MyMessage {
  string my_field = 1;
}

当部署到Cloud Endpoints时,字段名称将转换为camelCase.因此,如果我使用HTTP端点调用API,则JSON响应如下所示:

When deploying to Cloud Endpoints, the field names are converted to camelCase. So if I call the API using the HTTP endpoint, the JSON response looks like this:

{
  "myField":"field value"
}

如果我使用GRPC客户端(Node.js)调用服务,则将以原始格式返回响应对象:

If I call the service using a GRPC client (Node.js), the response object is returned in the original format:

{
  "my_field":"field value"
}

在Cloud Endpoints Developer Portal文档中,字段名称也转换为驼峰大小写.

The field names are also converted to camel case in the Cloud Endpoints Developer Portal documentation.

我希望对GRPC和HTTP客户端都使用蛇形保护套,因为我要替换现有的API.如果我可以防止字段名称被转换,则基本上可以将后端切换到新服务,而无需对客户端进行任何更改.

I'd prefer to use snake case for both GRPC and HTTP clients as I'm replacing an existing API. If I can prevent the field names from being converted, I can basically just switch the backend over to the new service without any changes to the client side.

在转码为HTTP/JSON时,是否有一种方法可以强制ESP使用驼峰式案例字段名称?

Is there a way to force ESP to use the camel case field names when transcoding to HTTP/JSON?

推荐答案

我将用ESP将grpc应用程序部署到k8s中,其下面的配置将把protobuf响应转码为蛇形而不是骆驼形

I'm deploy my grpc application in to k8s with ESP, with the config below it will transcoding the protobuf response to snake case instead of camel case

- name: esp
    image: gcr.io/endpoints-release/endpoints-runtime:1
    imagePullPolicy: Always
    args: [
      "--http_port=9000",
      "--backend=grpc://127.0.0.1:8080",
      "--service=xxxxxx",
      "--version=xxxxxx",
      "--transcoding_preserve_proto_field_names",
      "--transcoding_always_print_primitive_fields"
    ]
    ports:
    - name: http
      containerPort: 9000

这篇关于Google Cloud Endpoints(ESP)gRPC转码为驼峰式保护套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆