Closed schooltech closed 10 months ago
I cannot reproduce
package main
import (
"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cache"
"strings"
)
func SetupWebsocket(app *fiber.App) {
app.Use(cache.New(cache.Config{
Next: func(c *fiber.Ctx) bool {
return strings.Contains(c.Route().Path, "/ws")
},
}))
cfg := websocket.Config{
RecoverHandler: func(conn *websocket.Conn) {
if err := recover(); err != nil {
conn.WriteJSON(fiber.Map{"customError": "error occurred"})
}
},
}
app.Get("/ws/:id", websocket.New(func(c *websocket.Conn) {}, cfg))
}
func main() {
app := fiber.New()
SetupWebsocket(app)
app.Listen(":3000")
}
module testGo
go 1.20
require (
github.com/gofiber/contrib/websocket v1.3.0
github.com/gofiber/fiber/v2 v2.52.0
)
require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/fasthttp/websocket v1.5.7 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/klauspost/compress v1.17.3 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)
Can you clear your mod cache and try again?
I followed your method, just set up websocekt, and it was fine, but in my project, after cleaning the mod cache, the same error occurred, and my imported library looks like this: `module fiber-app
go 1.21.5
require ( github.com/casbin/casbin/v2 v2.81.0 github.com/casbin/xorm-adapter/v2 v2.5.1 github.com/gofiber/contrib/jwt v1.0.8 github.com/gofiber/contrib/websocket v1.3.0 github.com/gofiber/fiber/v2 v2.52.0 github.com/gofiber/session/v2 v2.0.2 github.com/gofiber/template/html/v2 v2.1.0 github.com/golang-jwt/jwt v3.2.2+incompatible github.com/gookit/validate v1.5.1 github.com/ilyakaznacheev/cleanenv v1.5.0 github.com/lib/pq v1.10.9 github.com/mojocn/base64Captcha v1.3.6 github.com/pkg/errors v0.9.1 github.com/redis/go-redis/v9 v9.4.0 github.com/sujit-baniya/flash v0.1.8 xorm.io/xorm v1.3.6 )
require ( github.com/BurntSushi/toml v1.2.1 // indirect github.com/MicahParks/keyfunc/v2 v2.1.0 // indirect github.com/andybalholm/brotli v1.0.5 // indirect github.com/casbin/govaluate v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/fasthttp/session/v2 v2.2.4 // indirect github.com/fasthttp/websocket v1.5.7 // indirect github.com/go-redis/redis/v8 v8.3.1 // indirect github.com/goccy/go-json v0.8.1 // indirect github.com/gofiber/template v1.8.2 // indirect github.com/gofiber/utils v1.1.0 // indirect github.com/golang-jwt/jwt/v5 v5.2.0 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/uuid v1.5.0 // indirect github.com/gookit/filter v1.2.0 // indirect github.com/gookit/goutil v0.6.12 // indirect github.com/joho/godotenv v1.5.1 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.17.3 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/philhofer/fwd v1.1.2 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/savsgio/dictpool v0.0.0-20200914121634-61efc2e36e16 // indirect github.com/savsgio/gotils v0.0.0-20230208104028-c358bd845dee // indirect github.com/syndtr/goleveldb v1.0.0 // indirect github.com/tinylib/msgp v1.1.8 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.51.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect go.opentelemetry.io/otel v0.13.0 // indirect golang.org/x/image v0.13.0 // indirect golang.org/x/sys v0.15.0 // indirect golang.org/x/text v0.13.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect xorm.io/builder v0.3.13 // indirect ) `
and the error like this: ` ... go: downloading modernc.org/token v1.0.1 go: downloading modernc.org/strutil v1.1.3 go: downloading lukechampine.com/uint128 v1.2.0 go: downloading golang.org/x/term v0.14.0 go: downloading golang.org/x/text v0.14.0 go: finding module for package github.com/savsgio/gotils go: fiber-app/appcfg imports github.com/gofiber/session/v2 imports github.com/fasthttp/session/v2 imports github.com/savsgio/gotils: module github.com/savsgio/gotils@latest found (v0.0.0-20230208104028-c358bd845dee), but does not contain package github.com/savsgio/gotils
`
but the tag is there https://pkg.go.dev/github.com/savsgio/gotils@v0.0.0-20230208104028-c358bd845dee since i don't have the other code that is causing your error, you have to find it by narrowing it down
thank you @ReneWerner87 , I found that when importing both the websocket and session libraries, I get a conflict error with the following code: `package main
import ( "github.com/gofiber/contrib/websocket" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cache" "github.com/gofiber/session/v2" "github.com/gofiber/session/v2/provider/redis" "strings" "time" )
var Session *session.Session
func SetupWebsocket(app fiber.App) { app.Use(cache.New(cache.Config{ Next: func(c fiber.Ctx) bool { return strings.Contains(c.Route().Path, "/ws") }, }))
cfg := websocket.Config{
RecoverHandler: func(conn *websocket.Conn) {
if err := recover(); err != nil {
conn.WriteJSON(fiber.Map{"customError": "error occurred"})
}
},
}
app.Get("/ws/:id", websocket.New(func(c *websocket.Conn) {}, cfg))
}
func SetupSession(app fiber.App) { provider, err := redis.New(redis.Config{ KeyPrefix: "verifyrest", Addr: "localhost:6379", PoolSize: 8, //nolint:gomnd IdleTimeout: 30 time.Second, //nolint:gomnd DB: 0, }) if err != nil { panic(err) }
Session = session.New(session.Config{
Provider: provider,
})
}
func main() { app := fiber.New()
SetupWebsocket(app)
SetupSession(app)
app.Listen(":3000")
} `
github.com/gofiber/session/v2 is deprecated Pls use it from the core
@ReneWerner87 thank you
Bug Description
github.com/gofiber/session/v2 imports github.com/fasthttp/session/v2 imports github.com/savsgio/gotils: module github.com/savsgio/gotils@latest found (v0.0.0-20230208104028-c358bd845dee), but does not contain package github.com/savsgio/gotils
How to Reproduce
when import github.com/gofiber/contrib/websocket
Expected Behavior
please fix the lib
Contrib package Version
v1.3.0
Code Snippet (optional)
Checklist: