go 中没有websocket这个库,需要安装第三方的库,这里选择常用的gorilla/websocket,
如下:
E:\Projects\CSMS\SK-CSMS\CentralSystem>go get -u github.com/gorilla/websocket
go: module github.com/gorilla/websocket: Get "https://proxy.golang.org/github.com/gorilla/websocket/@v/list": dial tcp 142.251.43.17:443: connectex: A connecti
on attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has fail
ed to respond.
就算开启了翻墙也一样,原因是中国大陆需要使用 GOPROXY=https://goproxy.cn,direct
如下:
E:\Projects\CSMS\SK-CSMS\CentralSystem>go env -w GOPROXY=https://goproxy.cn,direct
同时,在windows系统中系统变量增加
变量名: GOPROXY
然后检查一下
E:\Projects\CSMS\SK-CSMS\CentralSystem>go env GOPROXY
最后再 安装:
E:\Projects\CSMS\SK-CSMS\CentralSystem>go get -u github.com/gorilla/websocket
go: downloading github.com/gorilla/websocket v1.5.3
go: added github.com/gorilla/websocket v1.5.3
在 项目 目录 下的 go.mod:
module CentralSystem
go 1.22.4
require github.com/gorilla/websocket v1.5.3 // indirect
最后一行为自动新增的;
解决问题;
代码中引用:
import "github.com/gorilla/websocket"
标签:github,websocket,gorilla,go,com,CSMS From: https://blog.csdn.net/zhouwuhua/article/details/139693466