Description
runtime error: invalid memory address or nil pointer dereference,runtime error: invalid memory address or nil pointer dereference
runtime error: invalid memory address or nil pointer dereference
runtime error: invalid memory address or nil pointer dereference C:/src/runtime/panic.go:262 (0x3a3337) panicmem: panic(memoryError) C:/src/runtime/signal_windows.go:401 (0x3a3307) sigpanic: panicmem() C:/pkg/mod/gorm.io/gorm@v1.26.0/gorm.go:418 (0x522492) (*DB).getInstance: if db.clone > 0 { C:/pkg/mod/gorm.io/gorm@v1.26.0/chainable_api.go:113 (0x51c471) (*DB).Select: tx = db.getInstance() C:/pkg/User.go:20 (0x651bad) CheckUser: db.Select("id").Where("username = ?", name).First(&user) C:/pkg/user.go:18 (0x7b3504) AddUser: code = model.CheckUser(data.Username) C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/context.go:185 (0x7ad5ce) (*Context).Next: c.handlers[c.index](c) C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/recovery.go:102 (0x7ad5bb) CustomRecoveryWithWriter.func1: c.Next() C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/context.go:185 (0x7ac704) (*Context).Next: c.handlers[c.index](c) C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/logger.go:249 (0x7ac6eb) LoggerWithConfig.func1: c.Next() C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/context.go:185 (0x7abb51) (*Context).Next: c.handlers[c.index](c) C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/gin.go:633 (0x7ab5e0) (*Engine).handleHTTPRequest: c.Next() C:/pkg/mod/github.com/gin-gonic/gin@v1.10.0/gin.go:589 (0x7ab269) (*Engine).ServeHTTP: engine.handleHTTPRequest(c) C:/src/net/http/server.go:3301 (0x6a0a0d) serverHandler.ServeHTTP: handler.ServeHTTP(rw, req) C:/src/net/http/server.go:2102 (0x696a44) (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req) C:/src/runtime/asm_amd64.s:1700 (0x3c7180) goexit: BYTE $0x90 // NOP
Expected answer
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}
change
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{}
that's ok
Is this a bug? Or is there something wrong with the code I wrote?