登录
首页 >  Golang >  Go问答

main.go 找不到包

来源:stackoverflow

时间:2024-04-03 23:45:31 309浏览 收藏

学习知识要善于思考,思考,再思考!今天golang学习网小编就给大家带来《main.go 找不到包》,以下内容主要包含等知识点,如果你正在学习或准备学习Golang,就都不要错过本文啦~让我们一起来看看吧,能帮助到你就更好了!

问题内容

实际上我想使用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```` 而不是像示例中所示那样获取文件的 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 开发人员可以帮助我。


解决方案


main.go 文件无法在 /home/vinay/go/src/github.com/avalanche-io/c4/id 中找到包 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

以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于Golang的相关知识,也可关注golang学习网公众号。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>