Golang中第三方包安装方法-git

golang版本:go1.13.3
Goland版本:goland-2019.3
windows:win10
git版本:2.26.2 64位

主要参考以下原文实现
原文连接:https://studygolang.com/articles/5031
原文连接:https://studygolang.com/articles/5840
原文连接: https://www.idiot6.com/2019/07/23/go-gin-golang-x/?tdsourcetag=s_pctim_aiomsg
原文连接:https://cloud.tencent.com/developer/article/1376616
原文连接: https://blog.csdn.net/weixin_30319153/article/details/96842819
同时还感谢大神的指点
Golang中第三方包安装方法-git_第1张图片

首先,手动下载git文件进行安装,下载地址是https://git-scm.com/downloads
Golang中第三方包安装方法-git_第2张图片
Golang中第三方包安装方法-git_第3张图片
然后双击安装
Golang中第三方包安装方法-git_第4张图片
Golang中第三方包安装方法-git_第5张图片
Golang中第三方包安装方法-git_第6张图片
毕竟只是作为go的下载组件,就没必要创建开始菜单了
Golang中第三方包安装方法-git_第7张图片
设置git编辑器,我个人是有用Notepad++的,所以就选了它
Golang中第三方包安装方法-git_第8张图片
Golang中第三方包安装方法-git_第9张图片
Golang中第三方包安装方法-git_第10张图片
Golang中第三方包安装方法-git_第11张图片
Golang中第三方包安装方法-git_第12张图片
Golang中第三方包安装方法-git_第13张图片
在安装完后,配置对应的环境变量
Golang中第三方包安装方法-git_第14张图片
选择下载的包是https://github.com/gin-gonic/gin
Golang中第三方包安装方法-git_第15张图片
原文连接: https://www.idiot6.com/2019/07/23/go-gin-golang-x/?tdsourcetag=s_pctim_aiomsg
要设置go运行窗口环境,由于我的go是1.13的,所以要先输入

go env -w GOPROXY=https://goproxy.io,direct
go env -w GOPRIVATE=*.corp.example.com

对于1.13版本以前的,请用

$env:GO111MODULE="on"
$env:GOPROXY="https://goproxy.io"

然后再输入下载命令: go get github.com/gin-gonic/gin
不过需要科学上网才能下载
Golang中第三方包安装方法-git_第16张图片
安装完后你会发现在GoPath上会多出一个pkg文件夹,里面都是放你的安装的包
Golang中第三方包安装方法-git_第17张图片
Golang中第三方包安装方法-git_第18张图片
离线安装方法
首先,需要到https://github.com/Unknwon/com把源码下载下来。然后按照网址地址构建对应的文件夹,解压文件到对应的文件夹里面
Golang中第三方包安装方法-git_第19张图片
到这里后有两种选择,一种是采用辅助包的方法来安装,一种是直接手动安装。
手动安装方法:
这里我们以安装https://github.com/gpmgo/gopm这个包为例子。
首先,直接在https://github.com/gpmgo/gopm上下载源码压缩文件。然后按照网址地址构建对应的文件夹,解压文件到对应的文件夹里面。
Golang中第三方包安装方法-git_第20张图片
Golang中第三方包安装方法-git_第21张图片
然后输入

go install github.com/gpmgo/gopm

Golang中第三方包安装方法-git_第22张图片
这时候系统会自动创建bin文件夹,将包安装进去。
Golang中第三方包安装方法-git_第23张图片
辅助包的方法:
原文连接:https://cloud.tencent.com/developer/article/1376616
这里我以https://github.com/gin-gonic/gin这个包为安装对象
在使用前先要将上一块内容中生成gopm.exe移动到GO的安装路径下的bin中
Golang中第三方包安装方法-git_第24张图片
在GoPath\src下面输入

gopm get github.com/gin-gonic/gin

不过我这个并没有测试成功,一直提示连接有问题。
在这里插入图片描述
mod下载模式
原文连接: https://blog.csdn.net/weixin_30319153/article/details/96842819
测试对象包: https://github.com/astaxie/beego
Golang中第三方包安装方法-git_第25张图片
首先新建一个go文件,里面的内容如下

package main

import "github.com/astaxie/beego"

func main() {
	beego.Run()
}

运行结果提示是没有相关包的
Golang中第三方包安装方法-git_第26张图片
然后在目录下输入以下内容

go env -w GOPROXY=https://goproxy.io,direct
go env -w GOPRIVATE=*.corp.example.com
go mod init lesson2
go run lesson2

Golang中第三方包安装方法-git_第27张图片
文件会自动下载在你的第一个$GOPATH/pkg/mod中–github.com/astaxie/[email protected] 最后会有一个版本号 1.11.1,也就是说,$GOPATH/pkg/mod里可以保存相同包的不同版本。
Golang中第三方包安装方法-git_第28张图片
好了,大致就到此了。最近开始点亮go的技能,希望各位大神能多多指点。

你可能感兴趣的:(Z类分类_Golang)