[英]How do I correctly include golang protobuf/ptypes for protoc when using dep?
使用dep时,包括google / protobuf / timestamp.proto众所周知的类型在内,我遇到了麻烦。
我收到错误消息: 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;
}
安装包含timestamp .proto def的软件包:
dep ensure -add github.com/golang/protobuf/ptypes/timestamp
运行protoc
并获取错误:
build/bin/protoc -Ivendor -I. --twirp_typescript_out=version=v6:./clients/ts-json/ rpc/service.proto
google/protobuf/timestamp.proto: File not found.
存在包含时间戳的.proto定义的目录:
file vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.proto
vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.proto: ASCII text
我要在本地安装协议,因为我不想将协议版本锁定/绑定到该项目:
# 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
我究竟做错了什么?
您收到的protoc
错误与INCLUDE
路径有关。
当您安装protoc
编译器(例如/usr/local/bin/protoc
)时,要使用它来获取Google的标准proto定义(例如timestamp.proto
),则需要在INCLUDE
路径中的某些位置添加这些定义(在MacOS / Linux上可能是使用/usr/local/include
)。 注意:protoc标头应已包含在protoc编译器中。
因此,您的原型导入文件通常位于以下位置:
/usr/local/include/google/protobuf/timestamp.proto
当protoc
编译器看到如下所示的导入时,将引用此路径:
import "google/protobuf/timestamp.proto";
因此,请检查您的INCLUDE
路径,并确保正确安装了protoc
头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.