54、go mod使用——2020年07月11日15:46:14

54、go mod使用——2020年07月11日15:46:14

1、前提简介

github很多使用go的项目都是使用go mod集成库的,很多库也都是github上的项目。但是现在国内下载这些资源都比较不容易。我们需要配置一些配置才可以。

之前一直觉得go对国内用户太不友好了,一般都是各种库太难配置了!每次看到go的项目都很头痛。

2、配置国内源

链接资源:

go mod 国内镜像

https://ixu.me/go-mod.html

一键解决 go get golang.org/x 包失败

https://shockerli.net/post/go-get-golang-org-x-solution/

#开启GO111MODULE

// linux
export GO111MODULE=on



#goproxy.cn代理
#七牛也出了个国内代理 goproxy.cn 方便国内用户更快的访问不能访问的包,真是良心。

// linux
export GOPROXY=https://goproxy.cn



#脚本

download    download modules to local cache (下载依赖的module到本地cache))
edit        edit go.mod from tools or scripts (编辑go.mod文件)
graph       print module requirement graph (打印模块依赖图))
init        initialize new module in current directory (再当前文件夹下初始化一个新的module, 创建go.mod文件))
tidy        add missing and remove unused modules (增加丢失的module,去掉未用的module)
vendor      make vendored copy of dependencies (将依赖复制到vendor下)
verify      verify dependencies have expected content (校验依赖)
why         explain why packages or modules are needed (解释为什么需要依赖)

2、如何下载库

当clone了一个项目后,发现有go.mod文件时,可以使用以下命令:

go mod download

image-20200711155754791

image-20200711155846386

3、查看go的各种环境

go env

image-20200711160112201

END

2020年07月11日16:02:48

posted @ 2020-07-11 16:03  一颗小苹果  阅读(272)  评论(0编辑  收藏  举报