[golang]golang运行的一些报错解析
1、panic: runtime error: invalid memory address or nil pointer dereference
panic: runtime error: invalid memory address or nil pointer dereference 是 Go 语言中的一种常见运行时错误,表示程序试图访问一个未初始化或已经被释放的指针。要解决这个错误,你需要找到导致空指针引用的具体位置,并确保在访问指针之前对其进行初始化或检查。通过添加适当的错误处理和同步机制,可以有效避免这类问题。
2、go build -o main 下载包超时该如何解决:
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy
3、初始化golang项目问题解决
host@host-VMware-Virtual-Platform:~/rabbitmq_learn/websocket_study$ go mod init gin-websocket-demo
go: creating new go.mod: module gin-websocket-demo
go: to add module requirements and sums:
go mod tidy
host@host-VMware-Virtual-Platform:~/rabbitmq_learn/websocket_study$ go mod tidy
go: finding module for package github.com/gin-gonic/gin
go: finding module for package github.com/gorilla/websocket
go: gin-websocket-demo imports
github.com/gin-gonic/gin: module github.com/gin-gonic/gin: Get "https://proxy.golang.org/github.com/gin-gonic/gin/@v/list": dial tcp 142.251.215.241:443: connect: connection refused
go: gin-websocket-demo imports
github.com/gorilla/websocket: module github.com/gorilla/websocket: Get "https://proxy.golang.org/github.com/gorilla/websocket/@v/list": dial tcp 142.251.215.241:443: connect: connection refused
host@host-VMware-Virtual-Platform:~/rabbitmq_learn/websocket_study$
host@host-VMware-Virtual-Platform:~/rabbitmq_learn/websocket_study$
设置镜像即可解决
# 设置 GOPROXY 为阿里云镜像(推荐)
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/,direct
go mod tidy # 即可解决

浙公网安备 33010602011771号