go mod 包管理器

推荐官方自带 包管理器
安装好 go 之后 ,包管理器自带

以下不推荐

以下不推荐

以下不推荐

Gopm 包管理器

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

这个安装会自动生成执行文件 glide,文件一般位于 go/bin/目录下,所以 你这个目录要有可写权限哦,当然你这个命令也必须支持,否则无法生成

我的 go 目录放在用户根目录下:
mac系统
/Users/fox/go/go go 语言目录

Glide 命令

glide create 初始化项目并创建glide.yaml文件.
glide init 初始化项目并创建glide.yaml文件.
glide update 更新解析下载包依赖
glide up 更新解析下载包依赖
glide install 安装包
glide get 获取单个包
  --all-dependencies 会下载所有关联的依赖包
  -s 删除所有版本控制,如.git
  -v 删除嵌套的vendor
glide name 查看依赖名称
glide list 查看依赖列表
glide help 帮助
glide --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.yaml文件.在import:下一级增加

- 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.yaml文件.在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/crypto
- package: golang.org/x/tools
- package: golang.org/x/image

注意:这些包本项目都使用到,所有都加入

安装依赖

然后执行
glide install
会生成glide.lock文件,锁定安装包的版本

升级

这一步, 不是必须的,例如 你要升级某些包 可以执行

glide up

案例 已经使用Glide的项目

glide install

未完待续

golang 包管理工具相关推荐

  1. Golang包管理工具之govendor的使用

    本文个人博客地址为:http://www.huweihuang.com/article/golang/govendor-usage/ 本文个人博客地址为:https://huweihuang.net/ ...

  2. Golang包管理工具(三)之dep的使用

    本文个人博客地址:http://www.huweihuang.com/article/golang/dep-usage/ 更多golang包管理工具参考 - dep的使用 - glide的使用 - g ...

  3. Golang包管理工具govendor的使用

    1. govendor简介 golang工程的依赖包经常使用go get命令来获取,例如:go get github.com/kardianos/govendor ,会将依赖包下载到GOPATH的路径 ...

  4. Golang包管理工具(四)之go-modules的使用

    本文个人博客地址:https://www.huweihuang.com/golang-notes/introduction/package/go-modules.html 1. Go modules简 ...

  5. golang中的包管理工具——govendor和godep简单学习

    为什么用vendor目录 依赖问题 我们知道,一个工程稍大一点,通常会依赖各种各样的包.而Go使用统一的GOPATH管理依赖包,且每个包仅保留一个版本.而不同的依赖包由各自的版本工具独立管理,所以当所 ...

  6. Go (Golang) 工具之依赖包管理工具goimports | Go语言规范-import规范(导入)排序 |GoLand:设置gofmt与goimports,保存时自动格式化代码

    文章目录 Go (Golang) 工具之依赖包管理工具goimports Go语言规范-import(导入)排序 什么是goimports 安装和使用 Golang 使用goimports unrec ...

  7. Helm包管理工具(简介、安装、方法)

    认识Helm 每次我们要部署一个应用都需要写一个配置清单(维护一套yaml文件),但是每个环境又不一样.部署一套新的环境成本是真的很高.如果我们能够使用类似于yum的工具来安装我们的应用的话那就太好了 ...

  8. dep指定版本 go_Go 包管理工具-dep

    dep 是一个 golang 依赖管理工具,需要在 Go 1.7 及更高的版本中使用. 1. 安装 安装 dep 工具的方式有很多种,如果是 mac 电脑的话,只需要如下命令: brew instal ...

  9. Go:包管理工具GOPATH、vendor、dep 、go module

    目录 Go包管理工具:前言 GOPATH vendor.dep Go modules Module 文件 go mod命令 Go modules使用步骤: go module的文件下载后位置: Go包 ...

  10. 小白都能看懂的go语言包管理工具DEP详解

    简介 众所周知GO语言包管理工具百花齐放,前有godep.glide.govendor,后有dep. 今天我们来了解一下"dep",看看它是怎样实现包管理的. dep安装 二进制文 ...

最新文章

  1. ACM_无聊者序列(斐波那契数列大数取余(同余)+规律)
  2. 2 个月的面试亲身经历告诉大家,如何进入 BAT 等大厂?
  3. 配置纯净版Debian
  4. leetcode 1787. 使所有区间的异或结果为零
  5. 竞赛数据清洗缺失值_Kaggle 数据清洗挑战 Day 1 - 手把手教你五步处理缺失值
  6. [转]为elipse设置javadoc
  7. 如何解决JSP中文乱码问题
  8. 免费python编程自学网站-免费学习Python编程的3个优秀的网站资源
  9. rails kaminari bootstrap-kaminari-views certified
  10. 华为交换机的基本配置命令
  11. MSDC 4.3 接口规范(22)
  12. java生成PDF-支持中文及图片
  13. 软件测试的过程和产生的文档
  14. bing搜索PubHub发布商指南
  15. 计算机科学应用论文题目,比较好写的计算机科学与应用论文题目 计算机科学与应用论文题目怎么取...
  16. CentOS 各版本的下载
  17. GPS天线走线类型及注意事项
  18. dotnet 进行二进制差分压缩文件
  19. 冥冥之中——姥姥的喜丧
  20. 网页游戏开发入门教程

热门文章

  1. java如何操作视图
  2. VC学习笔记:状态栏
  3. sql 取一个月日期去掉周末的所有日期_LeetCode:SQL
  4. python判断给定的手机号是否存在
  5. 面试常问:BIO,NIO,AIO
  6. JSARToolKit5文档翻译
  7. java中struts2框架,概述Java的struts2框架
  8. 2021-06-06 下拉框,列表框..
  9. rsr分档matlab,matlab练习程序(dubins曲线)
  10. c语言除去字符串多余的空格,从一个字符串中去除多余的空格(用指针描述)...