My goal is to create a repository with multiple folders.
|- go.work
|- websocket
| |- go.mod
| |- go.sum
| |- server.go
|- channel
| |- main.go
The websocket uses github.com/gorilla/websocket package.
So, I need to do in the websocket folder.
$ go mod init github.com/kidfrom/learn-golang/websocket$ go get github.com/gorilla/[email protected]$ go work use .
The problem is, the websocket/go.mod throws warning
github.com/gorilla/websocket is not used in this module
If I do go mod tidy, the websocket/go.mod will be cleaned out and websocket/server.go will throws error
could not import github.com/gorilla/websocket (no required module provides package "github.com/gorilla/websocket")
TLDR
websocket/go.mod
module github.com/kidfrom/learn-golang/websocket
go 1.19
require github.com/gorilla/websocket v1.5.0 // indirect
websocket/go.sum
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/ ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55 EU/adAjf1fMHhE=
go.work
go 1.19
use (
./websocket
)
CodePudding user response:
First, make sure your server.go is in package main, as the original gorilla/websocket/examples/echo/server.go is.
Second, test if the name of the folder (which is also websocket) is an issue (conflicting with the websocket.xxx calls).
For testing, try and change it (and update go.work accordingly)
