繁体   English   中英

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

[英]Relative import in Go for protobuf , cannot find module path

我正在尝试使用 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)
}

环境

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"

回购https://github.com/zycon/cart-service

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

Go 中没有相对导入。 您可以查看此答案以获取扩展解释: Go 中的相对导入

有个提议: https : //github.com/golang/go/issues/20883

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM