[英]How do I correctly include golang protobuf/ptypes for protoc when using dep?
I'm having trouble including the google/protobuf/timestamp.proto well known type, when using dep . 使用dep时,包括google / protobuf / timestamp.proto众所周知的类型在内,我遇到了麻烦。
I get an error: google/protobuf/timestamp.proto: File not found
我收到错误消息:
google/protobuf/timestamp.proto: File not found
service.proto: 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: 安装包含timestamp .proto def的软件包:
dep ensure -add github.com/golang/protobuf/ptypes/timestamp
Run protoc
and get error: 运行
protoc
并获取错误:
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: 存在包含时间戳的.proto定义的目录:
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? 我究竟做错了什么?
The protoc
error you are getting relates to your INCLUDE
path. 您收到的
protoc
错误与INCLUDE
路径有关。
When you installed the protoc
compiler (eg 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
). 当您安装
protoc
编译器(例如/usr/local/bin/protoc
)时,要使用它来获取Google的标准proto定义(例如timestamp.proto
),则需要在INCLUDE
路径中的某些位置添加这些定义(在MacOS / Linux上可能是使用/usr/local/include
)。 Note: the protoc headers should have been included with the protoc compiler. 注意:protoc标头应已包含在protoc编译器中。
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: 当
protoc
编译器看到如下所示的导入时,将引用此路径:
import "google/protobuf/timestamp.proto";
So check your INCLUDE
path and ensure the protoc
headers are installed correctly. 因此,请检查您的
INCLUDE
路径,并确保正确安装了protoc
头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.