You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Timestamp类型部署Google gRPC Cloud Endpoints时遇部署错误

解决gRPC Cloud Endpoints部署时Timestamp类型的注释解析错误

刚踩过几乎一模一样的坑!你遇到的Unexpected end tag '--)' with missing begin tag错误,本质是protobuf文件的语法解析出了问题,和首次使用Timestamp类型的关联在于:要么是引入Timestamp的方式导致解析到了异常注释,要么是你自己的proto文件里藏着格式错误的注释。

给你几个排查和解决的具体步骤:

  • 先检查自身proto文件的注释格式
    错误提示里的--)是protobuf里用于选项注释的特定标记,但如果你的代码里只写了--)却没有对应的起始标记/*--,就会触发这个解析错误。仔细扫一遍你的proto文件,确保所有多行注释都是标准的/* ... */格式,单行注释用//,不要出现孤立的--)或者不配对的注释标签。

  • 确认Timestamp的引入方式正确
    确保你在proto文件里正确引入了官方的Timestamp定义:

    import "google/protobuf/timestamp.proto";
    

    同时要保证protoc编译环境能找到这个标准proto文件——如果是本地开发,要么把官方的protobuf标准文件放在protoc能识别的路径下,要么在编译命令里通过--proto_path参数指定标准库位置,比如:

    protoc --proto_path=./vendor/google/protobuf --go_out=./gen --go-grpc_out=./gen your_service.proto
    
  • 重新生成api_descriptor.pb文件
    有时候旧的descriptor文件可能缓存了错误内容,先删掉现有的api_descriptor.pb,重新用正确的protoc命令生成,再执行部署:

    rm api_descriptor.pb
    protoc --include_imports --include_source_info --descriptor_set_out=api_descriptor.pb your_service.proto
    gcloud endpoints deploy services api_descriptor.pb api_config.yaml
    
  • 快速排查api_config.yaml配置
    虽然错误提示指向proto文件,但也可以快速检查下api_config.yaml里有没有和Timestamp相关的错误映射,比如是否错误地把Timestamp类型写成了其他格式,不过这个概率相对低一些。

举个正确使用Timestamp的proto示例参考:

syntax = "proto3";

import "google/protobuf/timestamp.proto";

service UserService {
  rpc GetUser(GetUserRequest) returns (GetUserResponse);
}

message GetUserRequest {
  string user_id = 1;
}

message GetUserResponse {
  string name = 1;
  google.protobuf.Timestamp last_login_time = 2; // 正确使用Timestamp类型
}

按照上面的步骤排查,基本就能解决这个注释解析错误了。

内容的提问来源于stack exchange,提问作者user4653455

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:02:57