Go for protobuf中的相对导入,找不到模块路径 [英] Relative import in Go for protobuf , cannot find module path
本文介绍了Go for protobuf中的相对导入,找不到模块路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试与gRPC一起编写服务,并且当我导入protobuff文件时出现错误.我尝试删除go路径中的所有模块,然后重新初始化go模块
I'm trying to write a service in go with gRPC, and when i import the protobuff file , getting an error. i tried removing all the modules in my go path and reinitialising the go modules
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"
repo https://github.com/zycon/cart-service
推荐答案
将go.mod
移至根目录,并将导入更新为github.com/zycon/cart-service/pb
?
Move your go.mod
to the root and update import to github.com/zycon/cart-service/pb
?
Go中没有相对导入.您可以看到以下答案以获得更详细的解释: Go中的相对导入
There is no relative import in Go. You can see this answer for an extended explanation: Relative imports in Go
有一个建议: https://github.com/golang/go/issues/20883
这篇关于Go for protobuf中的相对导入,找不到模块路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文