一个GO模块的例子

栏目: Go · 发布时间: 5年前

内容简介:注意

起步

go mod需要 1.11

以后的版本才能使用

使用需要设置环境变量 GO111MODULE=on (可设置三个值,分别是 auto , on , off

新特性的使用暂时开关,还不确定以后会不会有

注意 go.mod 是可以自己手动编辑的,出现某些需要科学上网步骤,可以使用 replace 来完成模块的引入。

开始

#开启mod特性开关
export GO111MODULE=on

#拉取例子仓库
git clone https://github.com/flxxyz/go-mod-example.git && cd go-mod-example

#进入例子模块目录
cd src/example

#处理依赖
go mod tidy

#编译可执行文件(可选系统版本 mac,linux,linux64,windows,windows64)
make

#进入编译完成目录
cd ../../bin

#执行
./example -h

mod命令

  • go help mod 查看mod命令的帮助
  • go mod init <packageName> 初始化模块,目录下生成 go.mod
  • go mod tidy 根据 go.mod 文件来处理依赖关系
  • go list -m all 显示依赖文件
  • go mod download <path@version> 下载依赖(path是包的路径,version是包的版本)
  • go mod vendor 复制所有依赖到模块下的vendor目录
  • go mod graph 输出模块所需的依赖表
  • go mod verify 验证模块的完整性

来源

Go 1.11 Modules Wiki


以上所述就是小编给大家介绍的《一个GO模块的例子》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Security, Privacy and Commerce, 2nd Edition

Web Security, Privacy and Commerce, 2nd Edition

Simson Garfinkel / O'Reilly Media / 2002-01-15 / USD 44.95

Since the first edition of this classic reference was published, World Wide Web use has exploded and e-commerce has become a daily part of business and personal life. As Web use has grown, so have ......一起来看看 《Web Security, Privacy and Commerce, 2nd Edition》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具