我已經(jīng)創(chuàng)建了一個(gè)工作正常的 API,但出現(xiàn)了類似的錯(cuò)誤運(yùn)行時(shí)錯(cuò)誤:無(wú)效的內(nèi)存地址或零指針取消引用當(dāng)執(zhí)行單元測(cè)試代碼時(shí)。完整回復(fù)供您參考runtime error: invalid memory address or nil pointer dereferenceD:/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)
1 回答

元芳怎么了
TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超7個(gè)贊
在D:/Projects/GoLang/cloudfactory-backend/db/teams.go
在線中11
,您從零指針引用字段。如果沒(méi)有完整的源代碼(包括行號(hào)),就不可能精確定位,但它可能DBCon
沒(méi)有被初始化。
- 1 回答
- 0 關(guān)注
- 204 瀏覽
添加回答
舉報(bào)
0/150
提交
取消