枕上诗书闲处好,门前风景雨来佳。这篇文章主要讲述Go区块链开发手把手教你导入Go语言第三方库相关的知识,希望能为你提供帮助。
GO的命令 go get
让我们可以方便快捷的从网络中下载或更新Go语言包及其依赖文件,并将他们编译和安装。
- 先在命令行模式下输入
go --help
,可查看以下信息。
Go is a tool for managing Go source code.Usage:go <
command>
[arguments]The commands are:bugstart a bug report
buildcompile packages and dependencies
cleanremove object files and cached files
docshow documentation for package or symbol
envprint Go environment information
fixupdate packages to use new APIs
fmtgofmt (reformat) package sources
generategenerate Go files by processing source
getadd dependencies to current module and install them
installcompile and install packages and dependencies
listlist packages or modules
modmodule maintenance
runcompile and run Go program
testtest packages
toolrun specified go tool
versionprint Go version
vetreport likely mistakes in packagesUse "go help <
command>
" for more information about a command.Additional help topics:buildconstraint build constraints
buildmodebuild modes
ccalling between Go and C
cachebuild and test caching
environmentenvironment variables
filetypefile types
go.modthe go.mod file
gopathGOPATH environment variable
gopath-getlegacy GOPATH go get
goproxymodule proxy protocol
importpathimport path syntax
modulesmodules, module versions, and more
module-getmodule-aware go get
module-authmodule authentication using go.sum
module-privatemodule configuration for non-public modules
packagespackage lists and patterns
testflagtesting flags
testfunctesting functionsUse "go help <
topic>
" for more information about that topic.
我们可以看到
getadd dependencies to current module and install them
这就是我们今天要用到的东西。
然后查看它的帮助信息:
go get --help
usage: go get [-d] [-f] [-t] [-u] [-v] [-fix] [-insecure] [build flags] [packages]
Run \'go help get\' for details.
文章图片
文章图片
文章图片
找到我们要获取的库。
复制链接
https://github.com/go-sql-driver/mysql
使用
go get github.com/go-sql-driver/mysql
结果报错:
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/go-sql-driver/mysql: exec: "git": executable file not found in %PATH%
这里要安装Git,博主是安装了Git的,不过这里需要配置一下。
文章图片
在系统变量的PATH里面添加Git的bin目录的路径。
然后再运行
go get github.com/go-sql-driver/mysql
现在就成功了。
文章图片
这个
github.com/go-sql-driver/mysql
被称为远程导入路径,其实go get被称为远程动态导入GO包。其实 go get
干的事就是从分布式版本控制系统的仓库中找出代码包并将它编译以及安装。仓库名 | VCS | VCS | VCS |
---|---|---|---|
BitBucket | Mercurial | Git | |
GitHub | Git | ||
Google Code Project Hosting | Git | Mercurial | Subversion |
Launchpad | Bazaar |
go get
命令会将代码包远程导入路径与预置的代码托管站点的主域名进行匹配。如果匹配成功,则在对代码包远程导入路径的初步检查后返回正常的返回值或错误信息。如果匹配不成功,则会再对代码包远程导入路径进行动态分析。二、直接下载GO库
在 github 或者其他地方下载Go库。
文章图片
然后在系统变量查看GOPATH。
然后打开GOPATH的src目录
将文件复制进去。
文章图片
然后就成功获取了。
三、参数介绍
usage: go get [-d] [-f] [-t] [-u] [-v] [-fix] [-insecure] [build flags] [packages]
Run \'go help get\' for details.
然后我们可以看一看
go help get
里有关参数的介绍。The -d flag instructs get to stop after downloading the packages;
that is,
it instructs get not to install the packages.The -f flag, valid only when -u is set, forces get -u not to verify that
each package has been checked out from the source control repository
implied by its import path. This can be useful if the source is a local fork
of the original.The -fix flag instructs get to run the fix tool on the downloaded packages
before resolving dependencies or building the code.The -insecure flag permits fetching from repositories and resolving
custom domains using insecure schemes such as HTTP. Use with caution.The -t flag instructs get to also download the packages required to build
the tests for the specified packages.The -u flag instructs get to use the network to update the named packages
and their dependencies. By default, get uses the network to check out
missing packages but does not use it to look for updates to existing packages.The -v flag enables verbose progress and debug output.
【Go区块链开发手把手教你导入Go语言第三方库】简单来说就是:
- -d 下载完成后就停止工作,不安装库
- -f 这个参数只有在使用了-u 参数时才有用,强制-u不去验证import的每一个包是否已经获取了,这对本地fork的包非常有用。
- -fix 这个-fix参数表示在解决依赖关系或构建代码之前先运行fix工具。
- -insecure 该参数允许通过不安全(例如 HTTP)的自定义域获取并解析使用存储库。
- -t 该参数允许在下载该包时也下载测试该包需要的包。
- -u 参数允许 get 使用网络来更新包以及它们的依赖。默认情况下,get 使用网络检查丢失的包,但不使用它来查找现有包的更新。
- -v 启用详细进度和调试信息输出。
推荐阅读
- 重新学习C语言day05
- PhotonServer——实现客户端和服务器的通信(Unity实注册/登录)(上)
- 学会这5种JS函数继承方式,前端面试你至少成功50%
- Python中的函数参数(位置参数默认参数可变参数关键字参数和命名关键字参数)
- super-vlan 和 mux-vlan
- Netty-UDP与HTTPS协议
- Spark的两种核心Shuffle详解
- NAT原理总结iptables实现SNAT和DNAT。
- Java split函数的坑