英文:
How to implement go get within an app that has no internet?
问题
我正在玩一个使用martini的Go应用程序。每次运行应用程序时,我都必须运行"go get github.com/codegangsta/martini"。有没有办法不必这样做?无论如何,在离线环境中该如何工作?我正在考虑在没有互联网访问的离线环境中使用Go开发一个应用程序。
英文:
I am playing around with a Go app that imports martini for example. Every time I run the app, I have to run "go get github.com/codegangsta/martini". Any way to NOT have to do this? Either way, how would this work in an offline environment? I am considering Go for an app that will be offline with no internet access.
答案1
得分: 4
根据Go文档:
Get
命令会下载并安装由导入路径指定的包,以及它们的依赖项。
进一步解释一下:
go get
命令会从代码库中克隆你请求的代码(在这种情况下是github.com/codegangsta/martini
),以及该代码所导入的任何代码,并将其存储在本地的$GOPATH/src/
目录中,然后进行构建并存储,以便可以通过import
进行调用。因此,除非你的GOPATH
正在更改,否则你不需要多次调用go get
,并且在初始的go get
之后,它应该始终在本地可用。
英文:
From the go documentation:
Get downloads and installs the packages named by the import paths, along with their dependencies.
To expand on that:
go get
will clone the code you're requesting from the repository (in this case github.com/codegangsta/martini
) as well as any code that that code imports and store it in your local $GOPATH/src/
directory then build it and store it so that is available to call via import
, so you should never have to call go get
more than once unless your GOPATH
is being changed and it should always be available locally after the initial go get
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论