首页 > 解决方案 > main.go 找不到包

问题描述

实际上我想用它c4来生成c4 id 视频文件,所以我找到了下面repo是为做这件事而开发的,所以我克隆了这个repo https://github.com/Avalanche-io/c4/tree/v0.7.0

现在正如堆栈溢出的答案中所建议的那样:无法从 github 安装 cmd 版本的 c4

我在ubuntu终端中执行以下命令

go get github.com/Avalanche-io
go get github.com/Avalanche-io/c4/id
go get github.com/Avalanche-io/c4/cmd/c4

然后正如他们在如何使用它的示例中所示repo

package main

import (
  "fmt"
  "io"
  "os"

  c4 "github.com/avalanche-io/c4/id"
)

func main() {
  file := "main.go"
  f, err := os.Open(file)
  if err != nil {
    panic(err)
  }
  defer f.Close()

  // create a ID encoder.
  e := c4.NewEncoder()
  // the encoder is an io.Writer
  _, err = io.Copy(e, f)
  if err != nil {
    panic(err)
  }
  // ID will return a *c4.ID.
  // Be sure to be done writing bytes before calling ID()
  id := e.ID()
  // use the *c4.ID String method to get the c4id string
  fmt.Printf("C4id of \"%s\": %s\n", file, id)
  return
}

我只是复制了这个相同的示例并创建了一个main.go文件,当我运行他们在README.md https://github.com/Avalanche-io/c4/blob/v0.7.0/id/README.md中定义的 这个命令时是go run main.go ```` Instead of getting the 文件的 c4 id```,如他们在示例中所示。我收到以下错误

main.go:8:3: cannot find package "github.com/avalanche-io/c4/id" in any of:
    /usr/lib/go-1.13/src/github.com/avalanche-io/c4/id (from $GOROOT)
    /home/vinay/go/src/github.com/avalanche-io/c4/id (from $GOPATH)

我不懂go语言,所以在这里解决问题对我来说变得非常困难,有没有go开发人员可以帮助我。

标签: goc4go-get

解决方案


main.go文件无法找到github.com/avalanche-io/c4/id里面的包/home/vinay/go/src/github.com/avalanche-io/c4/id ,我可以看到你已经运行了以下go get 命令

go get github.com/Avalanche-io
go get github.com/Avalanche-io/c4/id
go get github.com/Avalanche-io/c4/cmd/c4

github.com/avalanche-io/c4/id 根据我的说法,它们都没有名称,您需要执行以下命令

go get github.com/avalanche-io/c4/id

现在只需运行你的 main.go

go run main.go

推荐阅读