protobuf的Go中的相对导入,找不到模块路径

protobuf的Go中的相对导入,找不到模块路径,go,protocol-buffers,go-modules,grpc-go,Go,Protocol Buffers,Go Modules,Grpc Go,我试图在go with gRPC中编写一个服务,当我导入protobuff文件时,得到一个错误。我尝试删除我的go路径中的所有模块,并重新初始化go模块 build _/Users/tibinlukose/cart-service/pb: cannot find module for path _/Users/tibinlukose/cart-service/pb 代码 环境 repo将您的go.mod移动到根目录,并将导入更新到github.com/zycon/cart service/pb

我试图在go with gRPC中编写一个服务,当我导入protobuff文件时,得到一个错误。我尝试删除我的go路径中的所有模块,并重新初始化go模块

build _/Users/tibinlukose/cart-service/pb: cannot find module for path _/Users/tibinlukose/cart-service/pb
代码

环境


repo

将您的
go.mod
移动到根目录,并将导入更新到
github.com/zycon/cart service/pb

Go中没有相对导入。您可以查看此答案以了解更多解释:


有一个建议:

Kewl,它可以工作,你能告诉我哪里出了问题吗,@Flimzy提到不要使用相对进口。
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)
}
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"