IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 区块链 -> 【Go区块链开发】手把手教你导入Go语言第三方库 -> 正文阅读

[区块链]【Go区块链开发】手把手教你导入Go语言第三方库

一、使用 go get获取

GO的命令 go get让我们可以方便快捷的从网络中下载或更新Go语言包及其依赖文件,并将他们编译和安装。

  1. 先在命令行模式下输入go --help,可查看以下信息。
Go is a tool for managing Go source code.

Usage:

        go <command> [arguments]

The commands are:

        bug         start a bug report
        build       compile packages and dependencies
        clean       remove object files and cached files
        doc         show documentation for package or symbol
        env         print Go environment information
        fix         update packages to use new APIs
        fmt         gofmt (reformat) package sources
        generate    generate Go files by processing source
        get         add dependencies to current module and install them
        install     compile and install packages and dependencies
        list        list packages or modules
        mod         module maintenance
        run         compile and run Go program
        test        test packages
        tool        run specified go tool
        version     print Go version
        vet         report likely mistakes in packages

Use "go help <command>" for more information about a command.

Additional help topics:

        buildconstraint build constraints
        buildmode       build modes
        c               calling between Go and C
        cache           build and test caching
        environment     environment variables
        filetype        file types
        go.mod          the go.mod file
        gopath          GOPATH environment variable
        gopath-get      legacy GOPATH go get
        goproxy         module proxy protocol
        importpath      import path syntax
        modules         modules, module versions, and more
        module-get      module-aware go get
        module-auth     module authentication using go.sum
        module-private  module configuration for non-public modules
        packages        package lists and patterns
        testflag        testing flags
        testfunc        testing functions

Use "go help <topic>" for more information about that topic.

我们可以看到 get add 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干的事就是从分布式版本控制系统的仓库中找出代码包并将它编译以及安装。

仓库名VCSVCSVCS
BitBucketMercurialGit
GitHubGit
Google Code Project HostingGitMercurialSubversion
LaunchpadBazaar

一般情况下,代码包远程导入路径中的第一个元素就是代码托管网站的主域名。在静态分析的时候,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.

简单来说就是:

  • -d 下载完成后就停止工作,不安装库
  • -f 这个参数只有在使用了-u 参数时才有用,强制-u不去验证import的每一个包是否已经获取了,这对本地fork的包非常有用。
  • -fix 这个-fix参数表示在解决依赖关系或构建代码之前先运行fix工具。
  • -insecure 该参数允许通过不安全(例如 HTTP)的自定义域获取并解析使用存储库。
  • -t 该参数允许在下载该包时也下载测试该包需要的包。
  • -u 参数允许 get 使用网络来更新包以及它们的依赖。默认情况下,get 使用网络检查丢失的包,但不使用它来查找现有包的更新。
  • -v 启用详细进度和调试信息输出。
  区块链 最新文章
盘点具备盈利潜力的几大加密板块,以及潜在
阅读笔记|让区块空间成为商品,打造Web3云
区块链1.0-比特币的数据结构
Team Finance被黑分析|黑客自建Token“瞒天
区块链≠绿色?波卡或成 Web3“生态环保”标
期货从入门到高深之手动交易系列D1课
以太坊基础---区块验证
进入以太坊合并的五个数字
经典同态加密算法Paillier解读 - 原理、实现
IPFS/Filecoin学习知识科普(四)
上一篇文章      下一篇文章      查看所有文章
加:2021-09-08 10:46:24  更:2021-09-08 10:47:17 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/5 7:53:35-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码