go install“不允许导入循环”

时间:2018-05-02 00:57:17

标签: go package cycle

伙计们 - 我无法理解这一点:

我的代码布局:

src / rtagent / rtagent.go(包主)

src / simplerouter / simplerouter.go(有包simplerouter)

src / p4 / p4runtime.pb.go(包p4)

rtagent.go:

package main
import (
    "fmt"
    "golang.org/x/net/context"
    "google.golang.org/grpc"
    "google.golang.org/grpc/reflection"
    "io"
    "log"
    "net"
    "p4"
    "simplerouter"
    p4_config "p4/config"
)

simplerouter.go

package simplerouter
import (
    "encoding/binary"
    "errors"
    "fmt"
    "p4"
    "p4InfoUtils"
    "strings"
    "unsafe"
)

p4runtime.pb.go

package p4
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import google_protobuf "github.com/golang/protobuf/ptypes/any"
import google_rpc "google.golang.org/genproto/googleapis/rpc/status"
import p4_config "p4/config"
import p41 "p4"
import (
    context "golang.org/x/net/context"
    grpc "google.golang.org/grpc"
)

我收到此错误:

go install rtagent
import cycle not allowed
package rtagent
        imports p4
        imports p4

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

错误信息几乎说明了一切:

rtagent导入p4,后者又导入p4(本身)。这是不允许的。

你的代码也很明显:

package p4
// <snip>
import p41 "p4"  // <-- importing itself