ZhangZhihui's Blog  
zzh@ZZHPC:~/zd/Github/RepoGo$ go work init
zzh@ZZHPC:~/zd/Github/RepoGo$ cd web-service-gin/
zzh@ZZHPC:~/zd/Github/RepoGo/web-service-gin$ go mod init github.com/ZhangZhihuiAAA/RepoGo/web-service-gin
zzh@ZZHPC:~/zd/Github/RepoGo/web-service-gin$ cd ..
zzh@ZZHPC:~/zd/Github/RepoGo$ go work use ./web-service-gin

go.mod names the module name. 

go.work uses the names of the directories of the modules.

zzh@ZZHPC:/zdata/Github$ go work init
zzh@ZZHPC:/zdata/Github$ go work use ./zimplebank
zzh@ZZHPC:/zdata/Github$ go work use ./orders-api
zzh@ZZHPC:/zdata/Github$ code .

 

This go.sum file contains the cryptographic checksums representing the content of the required packages.

The go.sum file isn’t designed to be human-editable and generally you won’t need to open it. But it serves two useful functions:

  • If you run the go mod verify command from your terminal, this will verify that the checksums of the downloaded packages on your machine match the entries in go.sum, so you can be confident that they haven’t been altered.
$ go mod verify
all modules verified
  • If someone else needs to download all the dependencies for the project — which they can do by running go mod download — they will get an error if there is any mismatch between the packages they are downloading and the checksums in the file.

 

So, in summary:

  • You (or someone else in the future) can run go mod download to download the exact versions of all the packages that your project needs.
  • You can run go mod verify to ensure that nothing in those downloaded packages has been changed unexpectedly.
  • Whenever you run go run , go test or go build , the exact package versions listed in go.mod will always be used.

 

posted on   ZhangZhihuiAAA  阅读(27)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
 
点击右上角即可分享
微信分享提示