golang 包管理工具
推荐官方自带 包管理器
安装好 go 之后 ,包管理器自带
http://gopm.io/
<h2>gopm 安装</h2> <pre><code class="lang-SHELL hljs">go get -u github.com/gpmgo/gopm </code></pre> <h2>gopm 使用案例</h2>安装 数据库 xormplus 操作
<pre><code class="lang-SHELL hljs">gopm get github.com/xormplus/xorm </code></pre> <h1>golang dep</h1>https://github.com/golang/dep
https://golang.github.io/dep/
其他安装方式
https://golang.github.io/dep/docs/installation.html
https://golang.github.io/dep/docs/new-project.html
<h1>Glide 介绍</h1>glide是Go的包管理工具。支持语义化版本,支持Git、Svn等,支持Go工具链,支持vendor目录,支持从Godep、GB、GPM、Gom倒入,支持私有的Repos和Forks。
http://glidedocs.readthedocs.io/zh/latest/ 中文版
https://glide.sh/ 官网
<h2>Glide 安装</h2> <pre><code class="lang-SHELL hljs">curl https://glide.sh/get | sh 或 go get github.com/Masterminds/glide </code></pre>这个安装会自动生成执行文件 <code>glide</code>,文件一般位于 <code>go/bin/</code>目录下,所以 你这个目录要有可写权限哦,当然你这个命令也必须支持,否则无法生成
我的 go 目录放在用户根目录下:
mac系统
<code>/Users/fox/go/go</code> go 语言目录
<code>glide create</code> 初始化项目并创建glide.yaml文件.
<code>glide init</code> 初始化项目并创建glide.yaml文件.
<code>glide update</code> 更新解析下载包依赖
<code>glide up</code> 更新解析下载包依赖
<code>glide install</code> 安装包
<code>glide get</code> 获取单个包
<code>--all-dependencies</code> 会下载所有关联的依赖包
<code>-s</code> 删除所有版本控制,如.git
<code>-v</code> 删除嵌套的vendor
<code>glide name</code> 查看依赖名称
<code>glide list</code> 查看依赖列表
<code>glide help</code> 帮助
<code>glide --version</code>查看版本
<code>glide mirror set [original] [replacement]</code> 替换包的镜像
<code>glide mirror set [original] [replacement] --vcs [type]</code> 替换包的镜像
<code>glide mirror remove [original]</code> 移除包的镜像
<code>glide mirror list</code> 获取包的镜像列表
https://www.golangtc.com/download/package
<h3>方法一 解决go get golang.org/x/net 安装失败</h3>使用过,还是会报错
<pre><code class="lang-SHELL hljs">glide mirror set https://golang.org/x/mobile https://github.com/golang/mobile --vcs git glide mirror set https://golang.org/x/crypto https://github.com/golang/crypto --vcs git glide mirror set https://golang.org/x/net https://github.com/golang/net --vcs git glide mirror set https://golang.org/x/tools https://github.com/golang/tools --vcs git glide mirror set https://golang.org/x/text https://github.com/golang/text --vcs git glide mirror set https://golang.org/x/image https://github.com/golang/image --vcs git glide mirror set https://golang.org/x/sys https://github.com/golang/sys --vcs git </code></pre>然后在 你的项目中,修改<code>glide.yaml</code>文件.在<code>import:</code>下一级增加
<pre><code class="lang-SHELL hljs">- package: golang.org/x/net </code></pre>注意:这些包,哪个包报错,增加报错的包,不要全部加入,只有使用到的包加入
例如
<pre><code class="lang-SHELL hljs">package: blog import: - package: golang.org/x/net - package: golang.org/x/sys - package: golang.org/x/mobile - package: golang.org/x/crypto - package: golang.org/x/text - package: golang.org/x/tools - package: golang.org/x/image 。。。。后面的不再复制了 </code></pre> <h3>方法二 下载包</h3> <pre><code class="lang-SHELL hljs">mkdir -p $GOPATH/src/golang.org/x cd $GOPATH/src/golang.org/x git clone https://github.com/golang/net.git #这个就是net包 git clone https://github.com/golang/crypto.git #这个就是crypto包 git clone https://github.com/golang/sys.git git clone https://github.com/golang/mobile.git git clone https://github.com/golang/text.git git clone https://github.com/golang/tools.git git clone https://github.com/golang/image.git ... 等等 需要的包,请自行替换 </code></pre> <h3>方法三 通过代理</h3>首先你要有一个代理,如果没有请请通过其他两个方法
在终端设置(这里设置,关闭终端就失效)
git 代理也要设置
<pre><code class="lang-SHELL hljs">git config --global http.proxy http://127.0.0.1:1080 #git config --global https.proxy https://127.0.0.1:1080 </code></pre>不需要代理的时候,可以关闭它
<pre><code class="lang-SHELL hljs">GIT 设置代理为空 git config --global --unset http.proxy #git config --global --unset https.proxy </code></pre>GIT 查看已经设置的值:
<pre><code class="lang-SHELL hljs">git config http.proxy </code></pre> <h2>Glide 生成的 glide.yml 文件说明</h2>请移步此链接查看
http://blog.csdn.net/chenqijing2/article/details/55050843
需要将 glide.yaml 和 glide.lock 进行版本控制
<h2>案例 没有使用Glide的项目</h2>从零开始使用.
下载
解压缩
<pre><code class="lang-SHELL hljs">unzip master.zip 解压缩后得到目录 blog-go-master </code></pre>移动目录
<pre><code class="lang-SHELL hljs">mv blog-go-master ~/blog-go </code></pre>添加环境变量把 这个目录加入GOPATH里面
找到你的 GOPATH 配置地方修改
进入目录
<pre><code class="lang-SHELL hljs">cd /Users/fox/blog-go/src/blog </code></pre> <h3>Glide 初始化</h3>执行
<pre><code class="lang-SHELL hljs">glide init </code></pre>输出
<pre><code class="lang-SHELL hljs">[INFO] Generating a YAML configuration file and guessing the dependencies [INFO] Attempting to import from other package managers (use --skip-import to skip) [INFO] Scanning code to look for dependencies [INFO] --> Found reference to github.com/astaxie/beego [INFO] --> Adding sub-package cache to github.com/astaxie/beego [INFO] --> Adding sub-package context to github.com/astaxie/beego [INFO] --> Adding sub-package httplib to github.com/astaxie/beego [INFO] --> Adding sub-package logs to github.com/astaxie/beego [INFO] --> Adding sub-package orm to github.com/astaxie/beego [INFO] --> Found reference to github.com/go-sql-driver/mysql [INFO] --> Found reference to github.com/qiniu/api.v7/auth/qbox [INFO] --> Adding sub-package storage to github.com/qiniu/api.v7 [INFO] --> Found reference to github.com/russross/blackfriday [INFO] --> Found reference to github.com/xormplus/xorm [INFO] --> Found test reference to github.com/smartystreets/goconvey/convey [INFO] Writing configuration file (glide.yaml) [INFO] Would you like Glide to help you find ways to improve your glide.yaml configuration? [INFO] If you want to revisit this step you can use the config-wizard command at any time. [INFO] Yes (Y) or No (N)? Y [INFO] Looking for dependencies to make suggestions on [INFO] --> Scanning for dependencies not using version ranges [INFO] --> Scanning for dependencies using commit ids [INFO] Gathering information on each dependency [INFO] --> This may take a moment. Especially on a codebase with many dependencies [INFO] --> Gathering release information for dependencies [INFO] --> Looking for dependency imports where versions are commit ids [INFO] Here are some suggestions... [INFO] The package github.com/astaxie/beego appears to have Semantic Version releases (http://semver.org). [INFO] The latest release is v1.9.2. You are currently not using a release. Would you like [INFO] to use this release? Yes (Y) or No (N) Y [INFO] Would you like to remember the previous decision and apply it to future [INFO] dependencies? Yes (Y) or No (N) Y [INFO] Updating github.com/astaxie/beego to use the release v1.9.2 instead of no release [INFO] The package github.com/astaxie/beego appears to use semantic versions (http://semver.org). [INFO] Would you like to track the latest minor or patch releases (major.minor.patch)? [INFO] The choices are: [INFO] - Tracking minor version releases would use '>= 1.9.2, < 2.0.0' ('^1.9.2') [INFO] - Tracking patch version releases would use '>= 1.9.2, < 1.10.0' ('~1.9.2') [INFO] - Skip using ranges [INFO] For more information on Glide versions and ranges see https://glide.sh/docs/versions [INFO] Minor (M), Patch (P), or Skip Ranges (S)? P [INFO] Would you like to remember the previous decision and apply it to future [INFO] dependencies? Yes (Y) or No (N) Y [INFO] Updating github.com/astaxie/beego to use the range ~1.9.2 instead of commit id v1.9.2 [INFO] Updating github.com/go-sql-driver/mysql to use the release v1.3 instead of no release [INFO] Updating github.com/go-sql-driver/mysql to use the range ~1.3.0 instead of commit id v1.3 [INFO] Updating github.com/qiniu/api.v7 to use the release v7.2.3 instead of no release [INFO] Updating github.com/qiniu/api.v7 to use the range ~7.2.3 instead of commit id v7.2.3 [INFO] Updating github.com/russross/blackfriday to use the release v2.0.0 instead of no release [INFO] Updating github.com/russross/blackfriday to use the range ~2.0.0 instead of commit id v2.0.0 [INFO] Updating github.com/smartystreets/goconvey to use the release 1.6.3 instead of no release [INFO] Updating github.com/smartystreets/goconvey to use the range ~1.6.3 instead of commit id 1.6.3 [INFO] Configuration changes have been made. Would you like to write these [INFO] changes to your configuration file? Yes (Y) or No (N) Y [INFO] Writing updates to configuration file (glide.yaml) [INFO] You can now edit the glide.yaml file.: [INFO] --> For more information on versions and ranges see https://glide.sh/docs/versions/ [INFO] --> For details on additional metadata see https://glide.sh/docs/glide.yaml/ </code></pre>第一次生成 glide.yaml 文件
<h2>golang 报错解决</h2> <pre><code class="lang-SHELL hljs">glide mirror set https://golang.org/x/mobile https://github.com/golang/mobile --vcs git glide mirror set https://golang.org/x/crypto https://github.com/golang/crypto --vcs git glide mirror set https://golang.org/x/net https://github.com/golang/net --vcs git glide mirror set https://golang.org/x/tools https://github.com/golang/tools --vcs git glide mirror set https://golang.org/x/text https://github.com/golang/text --vcs git glide mirror set https://golang.org/x/image https://github.com/golang/image --vcs git glide mirror set https://golang.org/x/sys https://github.com/golang/sys --vcs git </code></pre>在项目中,修改<code>glide.yaml</code>文件.在<code>import:</code>下一级增加
<pre><code class="lang-SHELL hljs">- package: golang.org/x/net - package: golang.org/x/sys - package: golang.org/x/mobile - package: golang.org/x/crypto - package: golang.org/x/text - package: golang.org/x/crypto - package: golang.org/x/tools - package: golang.org/x/image </code></pre>注意:这些包本项目都使用到,所有都加入
<h3>安装依赖</h3>然后执行
<code>glide install</code>
会生成glide.lock文件,锁定安装包的版本
这一步, 不是必须的,例如 你要升级某些包 可以执行
<pre><code class="lang-SHELL hljs">glide up </code></pre> <h2>案例 已经使用Glide的项目</h2> <pre><code class="lang-SHELL hljs">glide install </code></pre>未完待续
到此这篇关于“golang 包管理工具”的文章就介绍到这了,更多文章或继续浏览下面的相关文章,希望大家以后多多支持JQ教程网!您可能感兴趣的文章:
Golang笔记:包管理机制
golang Modules 依赖管理工具使用
gin-vue-admin 使用 go mod , golang开发工具 提示package gin-vue-admin/core is not in GOROOT
golang编译之vendor机制
go godep包管理工具详解
golang 动态生成函数_GoLang的优点和缺点
Go 语言包管理机制深入分析
Go 语言编程 — 程序运行环境
学习golang开始前的准备工作
Go 1.5之前的多种包管理机制简介(