go基础

 来自:https://blog.csdn.net/luosisan/article/details/124062564

1,新建项目基于gomodule

  新创建一个空目录test_mod,进入该目录,执行命令
  
 //easygo 为项目名称
  go mod init easygo

2,引入第三方依赖,比如引入定时任务

go get github.com/robfig/cron/v3

3,go mod tidy 就是去掉go.mod文件中项目不需要的依赖。

4, go mod edit   替换老的依赖

执行命令
go mod edit -replace [old git package]@[version]=[new git package]@[version]

例如
go mod edit -replace github.com/bndr/gojenkins=github.com/Bpazy/gojenkins@latest

方法二: 直接修改go.mod文件  

replace github.com/bndr/gojenkins => github.com/Bpazy/gojenkins v1.0.2-0.20200708084040-3655c428bba9     
即可完美解决此问题,replace 还有一个隐藏的秘密,那就是可引入本地项目代码   

     replace github.com/bndr/gojenkins => ../gojenkins

posted @ 2022-09-15 15:06  EasyCms-  阅读(23)  评论(0编辑  收藏  举报