我有一个 proto 文件product.proto
,我想在catalog.proto
. 我可以成功导入product.proto
,catalog.proto
但自动生成catalog.pb.go
的无法重新调整其依赖项的路径,即product.pb.go
. 它指出:
无法导入目录/pb/entities(在 /usr/local/go/src/catalog/pb/entities(来自 $GOROOT) /Users/trimulabs/go/src/中找不到包“catalog/pb/entities”目录/pb/entities(来自 $GOPATH))
目录结构
catalog
┣ main
┃ ┣ client.go
┃ ┗ server.go
┣ pb
┃ ┣ entities
┃ ┃ ┣ product.pb.go
┃ ┃ ┗ product.proto
┃ ┣ catalog.pb.go
┃ ┗ catalog.proto
目录.proto
syntax = "proto3";
package catalog;
import "catalog/pb/entities/product.proto";
service CatalogService {
rpc PostProduct (PostProductRequest) returns (PostProductResponse) {}
rpc GetProduct (GetProductRequest) returns (GetProductResponse) {}
rpc GetProducts (GetProductsRequest) returns (GetProductsResponse) {}
}
产品.proto
message Product {
string id = 1;
string name = 2;
string description = 3;
double price = 4;
}
message PostProductRequest {
string name = 1;
string description = 2;
double price = 3;
}
message PostProductResponse {
Product product = 1;
}
message GetProductRequest {
string id = 1;
}
message GetProductResponse {
Product product = 1;
}
message GetProductsRequest {
uint64 skip = 1;
uint64 take = 2;
repeated string ids = 3;
string query = 4;
}
message GetProductsResponse {
repeated Product products = 1;
}
有人可以帮忙吗?