我正在尝试与gRPC一起编写服务,并且当我导入protobuff文件时出现错误。我尝试删除go路径中的所有模块,然后重新初始化go模块
build _/Users/tibinlukose/cart-service/pb: cannot find module for path _/Users/tibinlukose/cart-service/pb
代码
package main
import (
pbcart "../pb/"
"log"
"fmt"
"google.golang.org/grpc"
"net"
)
var (
port = 1000;
)
type CartServiceServer struct {
}
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
fmt.Println("Server Starting ..")
lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", 10000))
if err != nil {
log.Fatal("unable to listen on the port")
}
serverOptions := []grpc.ServerOption{}
grpcServer := grpc.NewServer(serverOptions...)
srv := &CartServiceServer{}
pbcart.RegisterCartServiceServer(grpcServer, srv)
}
env
GOCACHE="/Users/tibinlukose/Library/Caches/go-build"
GOENV="/Users/tibinlukose/Library/Application Support/go/env"
GOPATH="/Users/tibinlukose/go"
GOROOT="/usr/local/Cellar/go/1.13.4/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.13.4/libexec/pkg/tool/darwin_amd64"
GOMOD="/Users/tibinlukose/cart-service/server/go.mod"
答案 0 :(得分:2)
将go.mod
移至根目录并更新导入到github.com/zycon/cart-service/pb
吗?
Go中没有相对导入。您可以看到以下答案以获取详细说明:Relative imports in Go