如何检查Golang中的缺失依赖项

huangapple go评论91阅读模式
英文:

how to check the missing dependencies in golang

问题

我可以使用以下方法来确定Go项目中缺少的依赖项:

  1. 使用go mod tidy命令来整理和更新项目的依赖项。该命令会自动检测并添加缺少的依赖项,并删除不再使用的依赖项。

  2. 使用go list命令来列出项目的所有依赖项。运行以下命令可以获取项目的所有直接和间接依赖项:

    go list -m all
    

    这将列出项目的所有依赖项及其版本信息。

  3. 使用go mod graph命令来查看项目的依赖图。运行以下命令可以获取项目的依赖图:

    go mod graph
    

    这将以图形方式显示项目的依赖关系,你可以从中找出缺少的依赖项。

希望这些方法能够帮助你确定Go项目中的缺失依赖项。

英文:

How can I know what are the missing dependencies in a go project?
Now the only way I know is to run the go build command and follow the error messages.

But is there any more efficient way to do that such as:

./a.out proj

and the return maybe like:

missing dependencies:
github.com/go-sql-driver/mysql
github.com/foo/bar
....

Does go build support this function?

答案1

得分: 1

由于Go是一种编译语言,所以为了查看代码是否有错误或缺少依赖项,需要编译代码。您可以使用go get作为go build的替代方法来查看缺少的依赖项。

一些参考资料来自文档

Go快速编译为机器代码,同时具有垃圾回收的便利性和运行时反射的强大功能。它是一种快速、静态类型、编译语言,感觉上像是一种动态类型、解释型语言。

英文:

Since Go is compiled language so in order to see if your code has an error or missing dependencies is by compiling your code. <br>
You can use go get as an alternative of go build to see your missing dependencies.

some reference from doc
> Go compiles quickly to machine code yet has the convenience of garbage
> collection and the power of run-time reflection. It's a fast,
> statically typed, compiled language that feels like a dynamically
> typed, interpreted language.

huangapple
  • 本文由 发表于 2017年1月11日 18:36:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/41588508.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定