dongluo8303 2019-06-11 20:57
浏览 237
已采纳

使用dep时,如何正确为协议添加golang protobuf / ptypes?

I'm having trouble including the google/protobuf/timestamp.proto well known type, when using dep.

I get an error: google/protobuf/timestamp.proto: File not found

service.proto:

syntax = "proto3";
import "google/protobuf/timestamp.proto";

package com.rynop.platform;
option go_package = "rpc";

service PlatformService {
  rpc Test(EmptyMessage) returns (EmptyMessage);
}

message EmptyMessage { }

message A {  
    string summary = 1;
    google.protobuf.Timestamp start = 2;
}

message B {
  repeated A foos = 1;
}

Install package containing timestamp .proto def:

dep ensure -add github.com/golang/protobuf/ptypes/timestamp 

Run protoc and get error:

build/bin/protoc -Ivendor -I. --twirp_typescript_out=version=v6:./clients/ts-json/ rpc/service.proto
google/protobuf/timestamp.proto: File not found.

The dir containing timestamp's .proto definition exists:

file vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.proto
vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.proto: ASCII text

I'm installing protoc locally because I wan't to lock-in/tie a protoc version to this project:

# fetch the protoc compiler
OS_NAME=$(shell uname -s)
ifeq ($(OS_NAME),Darwin)
    PROTOC_URL=https://github.com/google/protobuf/releases/download/v3.7.1/protoc-3.7.1-osx-x86_64.zip
endif
ifeq ($(OS_NAME),Linux)
    PROTOC_URL=https://github.com/google/protobuf/releases/download/v3.7.1/protoc-3.7.1-linux-x86_64.zip
endif
build/protoc build/bin/protoc:
    mkdir -p build/protoc/bin build/bin
    cd build/protoc && curl -L -o protoc.zip $(PROTOC_URL) && \
        unzip protoc.zip && mv bin/protoc ../bin/protoc

What am I doing wrong?

  • 写回答

1条回答 默认 最新

  • douang4294 2019-06-12 03:33
    关注

    The protoc error you are getting relates to your INCLUDE path.

    When you installed the protoc compiler (e.g. to /usr/local/bin/protoc), for it to pick up google's standard proto definitions like timestamp.proto - these need to be added somewhere along your INCLUDE path (on MacOS/Linux one may use /usr/local/include). Note: the protoc headers should have been included with the protoc compiler.

    So your proto import file would typically be located here:

    /usr/local/include/google/protobuf/timestamp.proto
    

    This path will be referenced when the protoc compiler sees an import like:

    import "google/protobuf/timestamp.proto";
    

    So check your INCLUDE path and ensure the protoc headers are installed correctly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格