我已经创建了一个工作正常的 API,但出现了类似的错误
运行时错误:无效的内存地址或零指针取消引用
当执行单元测试代码时。
完整回复供您参考
runtime error: invalid memory address or nil pointer dereference
D:/Go/src/runtime/panic.go:199 (0x447473)
panicmem: panic(memoryError)
D:/Go/src/runtime/signal_windows.go:233 (0x447320)
sigpanic: panicmem()
D:/Projects/GoLang/cloudfactory-backend/db/teams.go:11 (0xb49b36)
SelectAllTeams: func SelectAllTeams() (teams []models.Team, err error) {
D:/Projects/GoLang/cloudfactory-backend/services/teams.go:11 (0xbb09ec)
GetTeams: teams, err = db.SelectAllTeams()
D:/Projects/GoLang/cloudfactory-backend/controllers/api.go:32 (0xbb1b51)
ApiController.GetTeams: teams, err := services.GetTeams()
C:/Users/justin.joseph/go/pkg/mod/github.com/gin-gonic/gin@v1.4.0/context.go:124 (0x9f7da1)
(*Context).Next: c.handlers[c.index](c)
D:/Projects/GoLang/cloudfactory-backend/middlewares/db_logger.go:72 (0xc30430)
DBLogger.func1: c.Next()
C:/Users/justin.joseph/go/pkg/mod/github.com/gin-gonic/gin@v1.4.0/context.go:124 (0x9f7da1)
(*Context).Next: c.handlers[c.index](c)
C:/Users/justin.joseph/go/pkg/mod/github.com/gin-gonic/gin@v1.4.0/recovery.go:83 (0xa0b2ca)
RecoveryWithWriter.func1: c.Next()
C:/Users/justin.joseph/go/pkg/mod/github.com/gin-gonic/gin@v1.4.0/context.go:124 (0x9f7da1)
(*Context).Next: c.handlers[c.index](c)
C:/Users/justin.joseph/go/pkg/mod/github.com/gin-gonic/gin@v1.4.0/logger.go:240 (0xa0a357)
LoggerWithConfig.func1: c.Next()
C:/Users/justin.joseph/go/pkg/mod/github.com/gin-gonic/gin@v1.4.0/context.go:124 (0x9f7da1)
(*Context).Next: c.handlers[c.index](c)
C:/Users/justin.joseph/go/pkg/mod/github.com/gin-gonic/gin@v1.4.0/gin.go:389 (0xa01798)
(*Engine).handleHTTPRequest: c.Next()
C:/Users/justin.joseph/go/pkg/mod/github.com/gin-gonic/gin@v1.4.0/gin.go:351 (0xa00fba)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
元芳怎么了
相关分类