解决goland module代理无法访问
问题如下
D:\project\demo1\main>go run main.go
go: finding module for package github.com/sirupsen/logrus
main.go:4:2: module github.com/sirupsen/logrus: Get "https://proxy.golang.org/github.com/sirupsen/logrus/@v/list": dial tcp 172.217.27.145:443: connectex: A conn
ection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has fa
iled to respond.
分析上述报错可以看出是因为代理没有起作用的原因导致的
目录结构如下
package main
import (
log "github.com/sirupsen/logrus"
)
func main() {
log.WithFields(log.Fields{
"animal": "walrus",
}).Info("A walrus appears")
}
go.mod
module main
go 1.14
解决问题
ain>go env -w GOPROXY=https://goproxy.cn
再次执行
D:\project\demo1\main>go run main.go
go: finding module for package github.com/sirupsen/logrus
go: downloading github.com/sirupsen/logrus v1.6.0
D:\project\demo1\main>go mod init main
go mod init: go.mod already exists
成功
D:\project\demo1\main>go run main.go
time="2020-07-25T21:17:02+08:00" level=info msg="A walrus appears" animal=walrus
!