我的目標是創建一個包含多個文件夾的存儲庫。|- go.work|- websocket| |- go.mod| |- go.sum| |- server.go|- channel| |- main.gowebsocket 使用github.com/gorilla/websocket包。所以,我需要在websocket文件夾中做。$ go mod init github.com/kidfrom/learn-golang/websocket$ go get github.com/gorilla/[email protected]$ go work use .問題是,websocket/go.mod拋出警告github.com/gorilla/websocket is not used in this module如果我這樣做go mod tidy,websocket/go.mod將被清除并websocket/server.go拋出錯誤could not import github.com/gorilla/websocket (no required module provides package "github.com/gorilla/websocket")TLDRwebsocket/go.modmodule github.com/kidfrom/learn-golang/websocketgo 1.19require github.com/gorilla/websocket v1.5.0 // indirectwebsocket/go.sumgithub.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=websocket/server.gogo.workgo 1.19use ( ./websocket)
1 回答

嚕嚕噠
TA貢獻1784條經驗 獲得超7個贊
首先,確保您的server.go
內容package main
與原始內容一樣gorilla/websocket/examples/echo/server.go
。
其次,測試文件夾的名稱(也是) websocket
是否有問題(與websocket.xxx
調用沖突)。
為了測試,嘗試更改它(并go.work
相應地更新)
- 1 回答
- 0 關注
- 126 瀏覽
添加回答
舉報
0/150
提交
取消