网站首页 > 技术教程 正文
> # wget -c https://dl.google.com/go/go1.16.6.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local
> # vim /etc/profile
export PATH=$PATH:/usr/local/go/bin
> # source /etc/profile
配置 Goproxy 环境变量
Bash (Linux or macOS)
export GOPROXY=https://goproxy.io,direct
PowerShell (Windows)
$env:GOPROXY = "https://goproxy.io,direct"
使配置长久生效 (推荐)
上面的配置步骤只会当次终端内生效, 如何长久生效呢, 这样就不用每次都去配置环境变量了。
Mac/Linux
# 设置你的 bash 环境变量
echo "export GOPROXY=https://goproxy.io,direct" >> ~/.profile && source ~/.profile
# 如果你的终端是 zsh,使用以下命令
echo "export GOPROXY=https://goproxy.io,direct" >> ~/.zshrc && source ~/.zshrc
Windows
1. 右键 我的电脑 -> 属性 -> 高级系统设置 -> 环境变量
2. 在 "[你的用户名]的用户变量" 中点击 "新建" 按钮
3. 在 "变量名" 输入框并新增 "GOPROXY"
4. 在对应的 "变量值" 输入框中新增 "https://goproxy.io,direct"
5. 最后点击 "确定" 按钮保存设置
package main
import (
"fmt"
"github.com/robfig/cron"
)
func main() {
i := 0
c := cron.New()
spec := "*/5 * * * * ?"
c.AddFunc(spec, func() {
i++
fmt.Println("cron running:", i)
})
c.Start()
select {}
}
> # go run cron.go
cron.go:6:2: no required module provides package github.com/robfig/cron; to add it:
go get github.com/robfig/cron
解决方法:
> # go get github.com/robfig/cron
go: downloading github.com/robfig/cron v1.2.0
go get: added github.com/robfig/cron v1.2.0
> # go run cron.go
cron running: 1
cron running: 2
cron running: 3
> # go.mod
module test
go 1.16
require github.com/robfig/cron v1.2.0 // indirect
我们去掉 require github.com/robfig/cron v1.2.0 // indirect 这一行的内容
问题再次出现
> # go run cron.go
cron.go:6:2: no required module provides package github.com/robfig/cron; to add it:
go get github.com/robfig/cron
> # go get github.com/robfig/cron
go get: added github.com/robfig/cron v1.2.0
> # go run cron.go
cron running: 1
cron running: 2
cron running: 3
第二种方式: 手工添加
> # vim go.mod
module test
go 1.16
require (
github.com/robfig/cron
)
> # go mod tidy
go: errors parsing go.mod:
D:\test\go.mod:7:2: usage: require module/path v1.2.3
我们发现需要添加版本号
> # vim go.mod
module test
go 1.16
require (
github.com/robfig/cron v1
)
注意: 版本号需要自己去github.com去查询
> # go mod tidy
> # cat go.mod
module test
go 1.16
require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/apcera/termtables v0.0.0-20170405184538-bcbc5dc54055 // indirect
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/fxamacker/cbor/v2 v2.3.0
github.com/minio/minio-go/v7 v7.0.11
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/robfig/cron v1.2.0
github.com/scylladb/termtables v1.0.0
go.uber.org/zap v1.17.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
)
我们发现自动添加了 v1.2.0 版本号
> # go run cron.go
cron running: 1
cron running: 2
cron running: 3
猜你喜欢
- 2024-10-19 windows设置http代理 激活windows转到设置以激活怎么去掉
- 2024-10-19 360浏览器怎么设置代理IP?(内附教程)
- 2024-10-19 Win7系统电脑代理服务器的设置方法
- 2024-10-19 手机wifi怎么设置ip代理 手机网络怎么设置代理
- 2024-10-19 如何在Chrome,Edge,Safari和Firefox中更改用户代理
- 2024-10-19 动态住宅ip代理,这样设置,解决网络安全和访问限制问题!
- 2024-10-19 如何在IDM中设置代理服务器? idm代理ua
- 2024-10-19 软路由设置代理IP的步骤有哪些 软路由设置代理ip的步骤有哪些方法
- 2024-10-19 设置git代理 git设置ssh代理
- 2024-10-19 curl高级用法之设置代理服务器 curl代理ip
你 发表评论:
欢迎- 05-05从virsh当中学习QEMU/KVM启动命令
- 05-05Win10 BCD文件损坏怎么修复?(bcd文件损坏win7)
- 05-05亚马逊春节假期期间的店铺管理设置
- 05-051分钟总结常用k8s常用诊断教程(k8s常见故障)
- 05-05VisiPics重复图片查找软件中文汉化教程
- 05-05微服务的发布实现方式1灰度实现(微服务实现原理)
- 05-05轻松掌握Java多线程 - 第二章:线程的生命周期
- 05-05德拉诺之王邪DK报告:PVE向小测试及分析
- 最近发表
- 标签列表
-
- sd分区 (65)
- raid5数据恢复 (81)
- 地址转换 (73)
- 手机存储卡根目录 (55)
- tcp端口 (74)
- project server (59)
- 双击ctrl (55)
- 鼠标 单击变双击 (67)
- debugview (59)
- 字符动画 (65)
- flushdns (57)
- ps复制快捷键 (57)
- 清除系统垃圾代码 (58)
- web服务器的架设 (67)
- 16进制转换 (69)
- xclient (55)
- ps源文件 (67)
- filezilla server (59)
- 句柄无效 (56)
- word页眉页脚设置 (59)
- ansys实例 (56)
- 6 1 3固件 (59)
- sqlserver2000挂起 (59)
- vm虚拟主机 (55)
- config (61)
本文暂时没有评论,来添加一个吧(●'◡'●)