如何列出已安装的 go 包 [英] How to list installed go packages

查看:27
本文介绍了如何列出已安装的 go 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知go distribution带有某种包管理器.go 1.4.1 安装后,我运行了 go help 以找到任何能够列出本地安装的 go 包 的子命令,但是不幸的是没有.

To my knowledge go distribution comes with some sort of package manager. After go 1.4.1 installation I've run go help in order to find any sub-command capable of listing locally installed go packages, but unfortunately got none.

那怎么办呢?

推荐答案

goinstall 现已成为历史

goinstall 被替换为 go get.go get 用于管理外部/第 3 方库(例如下载、更新、安装等).

goinstall is now history

goinstall was replaced by go get. go get is used to manage external / 3rd party libraries (e.g. to download them, update them, install them etc).

输入 go help get 以查看命令行帮助,或查看以下页面:

Type go help get to see command line help, or check out these pages:

Command go

关于 go 命令(博客文章)

如果要列出已安装的软件包,可以使用 go list 命令来完成:

If you want to list installed packages, you can do that with the go list command:

要列出工作区中的包,请转到工作区文件夹并运行以下命令:

To list packages in your workspace, go to your workspace folder and run this command:

go list ./...

./ 告诉从当前文件夹开始,... 告诉递归下去.当然,这不仅适用于您的 go 工作区中的任何其他文件夹(但通常这是您感兴趣的).

./ tells to start from the current folder, ... tells to go down recursively. Of course this works in any other folders not just in your go workspace (but usually that is what you're interested in).

执行

go list ...

在任何文件夹中列出所有包,包括标准库的包,然后是 go 工作区中的外部库.

in any folder lists all the packages, including packages of the standard library first followed by external libraries in your go workspace.

如果您还想查看每个包导入的包,可以尝试这种自定义格式:

If you also want to see the imported packages by each package, you can try this custom format:

go list -f "{{.ImportPath}} {{.Imports}}" ./...

-f 指定列表的替代格式,使用包 模板.可以通过go help list 命令打印其字段可以被引用的结构体.

-f specifies an alternate format for the list, using the syntax of package template. The struct whose fields can be referenced can be printed by the go help list command.

如果你想recursively查看所有的依赖(递归导入的包的依赖),你可以使用这个自定义格式:

If you want to see all the dependencies recursively (dependencies of imported packages recursively), you can use this custom format:

go list -f "{{.ImportPath}} {{.Deps}}" ./...

但通常这是一个很长的列表,您想要的只是每个包的单个导入("{{.Imports}}").

But usually this is a long list and just the single imports ("{{.Imports}}") of each package is what you want.

另见相关问题:Go 是什么(mod) 相当于 npm-outdated?

这篇关于如何列出已安装的 go 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆