I have spent hours trying to read blogs on how to use simple proto file in Golang. I generated the .pb.go files. All internet examples are littered with doing import from some random "github...
urls for proto import. I am not able to find any example on how to import a simple proto file that exists in same dir as my .go file or diff directory. How do I use proto files from local file systems.
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 of hello.go
in $SOME_DIR/customer
package main
import (
"fmt"
pb "customer"
)
func main() {
fmt.Println("hello test message
")
}
Contents of 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;
}