我已经创建了一个工作正常的 API,但出现了类似的错误运行时错误:无效的内存地址或零指针取消引用当执行单元测试代码时。完整回复供您参考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贡献1798条经验 获得超7个赞
在D:/Projects/GoLang/cloudfactory-backend/db/teams.go
在线中11
,您从零指针引用字段。如果没有完整的源代码(包括行号),就不可能精确定位,但它可能DBCon
没有被初始化。
- 1 回答
- 0 关注
- 146 浏览
添加回答
举报
0/150
提交
取消