好好爱自己!

go mod 解决 Go 语言的包依赖问题

转:https://testerhome.com/topics/16980

https://testerhome.com/

----------------------------------------------

go mod 解决 Go 语言的包依赖问题

codeskyblue · 2018年11月22日 · 最后由  回复于 2018年11月23日 · 2695 次阅读

受众

学习过Go的人,入门即可

go mod命令

随着Go 1.11的发布,go开始支持mod子命令

这个命令解决了Go依赖更新的问题。刚开始学起来有一点难度,不过学会了之后,会发现这玩意比原来的 vendor好太多。
官方还专门弄了一个https://goproxy.io网站,专门方便我们这些国内的用户。

先看下自带的帮助。

$ go mod
Go mod provides access to operations on modules.

Note that support for modules is built into all the go commands,
not just 'go mod'. For example, day-to-day adding, removing, upgrading,
and downgrading of dependencies should be done using 'go get'.
See 'go help modules' for an overview of module functionality.

Usage:

        go mod <command> [arguments]

The commands are:

        download    download modules to local cache
        edit        edit go.mod from tools or scripts
        graph       print module requirement graph
        init        initialize new module in current directory
        tidy        add missing and remove unused modules
        vendor      make vendored copy of dependencies
        verify      verify dependencies have expected content
        why         explain why packages or modules are needed

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

想学好go mod命令,推荐3篇文章,阅读顺序有先后。

  1. https://roberto.selbach.ca/intro-to-go-modules/

    这是Roberto Selbach大神写的这篇 Step by step的 go mod入门文章,非常好理解

  2. https://github.com/golang/go/wiki/Modules

    go mod的官方文档,想了解的多一点最好还是通读一下

  3. https://roberto.selbach.ca/go-proxies/

    最后还有一篇介绍GOPROXY的文章,比较适合对go mod熟悉之后再看

使用感受

感觉go mod应该是受了 npm 的package.json 启发,总体而言比过去的vendor好了很多,但是如果要修改依赖库,还需要再重新发布个版本,感觉调试起来不是很方便。

posted @   立志做一个好的程序员  阅读(1364)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
历史上的今天:
2018-05-22 fabricjs 自定义类型
2015-05-22 我也谈 javascript 模块化 -AMD规范

不断学习创作,与自己快乐相处

点击右上角即可分享
微信分享提示