我花了数小时试图阅读有关如何在Golang中使用简单原型文件的博客。我生成了.pb.go文件。所有互联网示例都充斥着从某些随机"github...
URL进行导入以进行原型导入的麻烦。我找不到任何有关如何导入与我的.go文件或diff目录相同目录的简单原型文件的示例。如何使用本地文件系统中的原始文件。
go build hello.go
hello.go:5:2: cannot find package "customer" in any of:
/usr/local/go/src/customer (from $GOROOT)
/Users/myhomedir/go/src/customer (from $GOPATH)
的Contentes hello.go
在$ SOME_DIR /客户
package main
import (
"fmt"
pb "customer"
)
func main() {
fmt.Println("hello test message\n")
}
内容 customer.proto
syntax = "proto3";
package customer;
// The Customer service definition.
service Customer {
// Get all Customers with filter - A server-to-client streaming RPC.
rpc GetCustomers(CustomerFilter) returns (stream CustomerRequest) {}
// Create a new Customer - A simple RPC
rpc CreateCustomer (CustomerRequest) returns (CustomerResponse) {}
}
// Request message for creating a new customer
message CustomerRequest {
int32 id = 1; // Unique ID number for a Customer.
string name = 2;
string email = 3;
string phone= 4;
message Address {
string street = 1;
string city = 2;
string state = 3;
string zip = 4;
bool isShippingAddress = 5;
}
repeated Address addresses = 5;
}
message CustomerResponse {
int32 id = 1;
bool success = 2;
}
message CustomerFilter {
string keyword = 1;
}
只需将客户代码放在目录中,然后像打包程序一样将其导入
package main
import "$SOME_DIR/customer"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句