推荐官方自带 包管理器
安装好 go 之后 ,包管理器自带
http://gopm.io/
gopm 安装
go get -u github.com/gpmgo/gopm
gopm 使用案例
安装 数据库 xormplus 操作
gopm get github.com/xormplus/xorm
golang dep
https://github.com/golang/dep
https://golang.github.io/dep/
golang dep 安装
go get -u github.com/golang/dep/cmd/dep
其他安装方式
https://golang.github.io/dep/docs/installation.html
golang dep 如何使用
https://golang.github.io/dep/docs/new-project.html
Glide 介绍glide是Go的包管理工具。支持语义化版本,支持Git、Svn等,支持Go工具链,支持vendor目录,支持从Godep、GB、GPM、Gom倒入,支持私有的Repos和Forks。
http://glidedocs.readthedocs.io/zh/latest/ 中文版
https://glide.sh/ 官网
Glide 安装
curl https://glide.sh/get | sh
或
go get github.com/Masterminds/glide
glidego/bin/
/Users/fox/go/go
Glide 命令
glide createglide initglide updateglide upglide installglide get--all-dependencies-s-vglide nameglide listglide helpglide --version
glide mirror set [original] [replacement]glide mirror set [original] [replacement] --vcs [type]glide mirror remove [original]glide mirror list
Golang类库 下载
https://www.golangtc.com/download/package
方法一 解决go get golang.org/x/net 安装失败
使用过,还是会报错
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
glide.yamlimport:
- package: golang.org/x/net
注意:这些包,哪个包报错,增加报错的包,不要全部加入,只有使用到的包加入
例如
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
。。。。后面的不再复制了
方法二 下载包
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
... 等等 需要的包,请自行替换
方法三 通过代理
首先你要有一个代理,如果没有请请通过其他两个方法
在终端设置(这里设置,关闭终端就失效)
export http_proxy=http://127.0.1:9000
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
git 代理也要设置
git config --global http.proxy http://127.0.0.1:1080
#git config --global https.proxy https://127.0.0.1:1080
不需要代理的时候,可以关闭它
GIT 设置代理为空
git config --global --unset http.proxy
#git config --global --unset https.proxy
GIT 查看已经设置的值:
git config http.proxy
Glide 生成的 glide.yml 文件说明
请移步此链接查看
http://blog.csdn.net/chenqijing2/article/details/55050843
Glide 团队开发时
需要将 glide.yaml 和 glide.lock 进行版本控制
案例 没有使用Glide的项目
从零开始使用.
下载
wget https://github.com/foxiswho/blog-go/archive/master.zip
解压缩
unzip master.zip
解压缩后得到目录 blog-go-master
移动目录
mv blog-go-master ~/blog-go
添加环境变量把 这个目录加入GOPATH里面
找到你的 GOPATH 配置地方修改
export GOPATH=/Users/fox/go/gopath:/Users/fox/blog-go
进入目录
cd /Users/fox/blog-go/src/blog
Glide 初始化
执行
glide init
输出
[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/
第一次生成 glide.yaml 文件
golang 报错解决
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
glide.yamlimport:
- 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
注意:这些包本项目都使用到,所有都加入
安装依赖
glide install
升级
这一步, 不是必须的,例如 你要升级某些包 可以执行
glide up
案例 已经使用Glide的项目
glide install
未完待续