runtime error: invalid memory address or nil pointer dereference错误

来源:5-13 商品管理功能Controller&View开发 (中)

慕粉慕粉1888

2020-03-11

http server启动了,但是访问http://localhost:8080/product/all,出现如下错误
product/add没问题

[DBUG] 2020/03/11 11:11 HEAD: /assets/*file -> github.com/kataras/iris/core/router.StripPrefix.func1()
[DBUG] 2020/03/11 11:11 GET: /assets/*file -> github.com/kataras/iris/core/router.StripPrefix.func1()
[DBUG] 2020/03/11 11:11 GET: /product/add -> controllers.ProductController.GetAdd()
[DBUG] 2020/03/11 11:11 GET: /product/all -> controllers.ProductController.GetAll()
[DBUG] 2020/03/11 11:11 POST: /product/add -> controllers.ProductController.PostAdd()
[DBUG] 2020/03/11 11:11 POST: /product/update -> controllers.ProductController.PostUpdate()
[DBUG] 2020/03/11 11:11 Application: 1 registered view engine(s)
[DBUG] 2020/03/11 11:11 Application: running using 1 host(s)
[DBUG] 2020/03/11 11:11 Host: addr is localhost:8080
[DBUG] 2020/03/11 11:11 Host: virtual host is localhost:8080
[DBUG] 2020/03/11 11:11 Host: register startup notifier
[DBUG] 2020/03/11 11:11 Host: register server shutdown on interrupt(CTRL+C/CMD+C)
[DBUG] 2020/03/11 11:11 Host: server will ignore the following errors: [http: Server closed]
Now listening on: http://localhost:8080
Application started. Press CMD+C to shut down.
[HTTP Server] http: panic serving 127.0.0.1:50416: runtime error: invalid memory address or nil pointer dereference
goroutine 22 [running]:
net/http.(*conn).serve.func1(0xc0001c2000)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1767 +0x139
panic(0x1609920, 0x1c083a0)
	/usr/local/Cellar/go/1.13.6/libexec/src/runtime/panic.go:679 +0x1b2
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3063 +0x72
database/sql.(*Rows).Close(0x0, 0xc000133270, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3059 +0x33
imooc-product/repositories.(*ProductManager).SelectAll(0xc00032fc40, 0x0, 0x0, 0x0, 0x17c3c20, 0xc0004fd770)
	/Users/xxd/go/src/imooc-product/repositories/product_repository.go:138 +0x370
imooc-product/services.(*ProductService).GetAllProduct(0xc0001325b0, 0x1c3b300, 0x0, 0xc0001d15d0, 0x100dc36, 0xc0004fd720)
	/Users/xxd/go/src/imooc-product/services/product_service.go:31 +0x33
imooc-product/backend/web/controllers.(*ProductController).GetAll(0xc0003e86a0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/xxd/go/src/imooc-product/backend/web/controllers/product_controller.go:17 +0x61
reflect.Value.call(0x162eac0, 0xc0003e86a0, 0x613, 0x16bda2c, 0x4, 0x1c3a1e0, 0x0, 0x0, 0x4, 0xc0001d18a0, ...)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:460 +0x5f6
reflect.Value.Call(0x162eac0, 0xc0003e86a0, 0x613, 0x1c3a1e0, 0x0, 0x0, 0x613, 0x30, 0x203000)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:321 +0xb4
github.com/kataras/iris/mvc.(*ControllerActivator).handlerOf.func2(0x17e5000, 0xc0000c4510)
	/Users/xxd/go/src/github.com/kataras/iris/mvc/controller.go:409 +0x5b2
github.com/kataras/iris/context.Do(0x17e5000, 0xc0000c4510, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:922 +0x81
github.com/kataras/iris/context.(*context).Do(0xc0000c4510, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:1094 +0x55
github.com/kataras/iris/core/router.(*routerHandler).HandleRequest(0xc0003e82a0, 0x17e5000, 0xc0000c4510)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/handler.go:227 +0x55c
github.com/kataras/iris/core/router.(*Router).BuildRouter.func1(0x17ced20, 0xc0000fe9a0, 0xc000156100)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:84 +0x8f
github.com/kataras/iris/core/router.(*Router).ServeHTTP(0xc000151880, 0x17ced20, 0xc0000fe9a0, 0xc000156100)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:161 +0x48
net/http.serverHandler.ServeHTTP(0xc0000fe8c0, 0x17ced20, 0xc0000fe9a0, 0xc000156100)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc0001c2000, 0x17d0860, 0xc000196080)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2928 +0x384
[HTTP Server] http: panic serving 127.0.0.1:50418: runtime error: invalid memory address or nil pointer dereference
goroutine 23 [running]:
net/http.(*conn).serve.func1(0xc0001c20a0)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1767 +0x139
panic(0x1609920, 0x1c083a0)
	/usr/local/Cellar/go/1.13.6/libexec/src/runtime/panic.go:679 +0x1b2
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3063 +0x72
database/sql.(*Rows).Close(0x0, 0xc000133280, 0x163b720)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3059 +0x33
imooc-product/repositories.(*ProductManager).SelectAll(0xc00032fc40, 0x0, 0x0, 0x0, 0x17c3c20, 0xc0004fd860)
	/Users/xxd/go/src/imooc-product/repositories/product_repository.go:138 +0x370
imooc-product/services.(*ProductService).GetAllProduct(0xc0001325b0, 0x1c3b300, 0x0, 0xc0001d15d0, 0x100dc36, 0xc0004fd810)
	/Users/xxd/go/src/imooc-product/services/product_service.go:31 +0x33
imooc-product/backend/web/controllers.(*ProductController).GetAll(0xc0003e87a0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/xxd/go/src/imooc-product/backend/web/controllers/product_controller.go:17 +0x61
reflect.Value.call(0x162eac0, 0xc0003e87a0, 0x613, 0x16bda2c, 0x4, 0x1c3a1e0, 0x0, 0x0, 0x4, 0xc0000538a0, ...)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:460 +0x5f6
reflect.Value.Call(0x162eac0, 0xc0003e87a0, 0x613, 0x1c3a1e0, 0x0, 0x0, 0x613, 0x0, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:321 +0xb4
github.com/kataras/iris/mvc.(*ControllerActivator).handlerOf.func2(0x17e5000, 0xc0000c4630)
	/Users/xxd/go/src/github.com/kataras/iris/mvc/controller.go:409 +0x5b2
github.com/kataras/iris/context.Do(0x17e5000, 0xc0000c4630, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:922 +0x81
github.com/kataras/iris/context.(*context).Do(0xc0000c4630, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:1094 +0x55
github.com/kataras/iris/core/router.(*routerHandler).HandleRequest(0xc0003e82a0, 0x17e5000, 0xc0000c4630)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/handler.go:227 +0x55c
github.com/kataras/iris/core/router.(*Router).BuildRouter.func1(0x17ced20, 0xc0000fea80, 0xc000156200)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:84 +0x8f
github.com/kataras/iris/core/router.(*Router).ServeHTTP(0xc000151880, 0x17ced20, 0xc0000fea80, 0xc000156200)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:161 +0x48
net/http.serverHandler.ServeHTTP(0xc0000fe8c0, 0x17ced20, 0xc0000fea80, 0xc000156200)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc0001c20a0, 0x17d0860, 0xc000196280)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2928 +0x384
[HTTP Server] http: panic serving 127.0.0.1:50422: runtime error: invalid memory address or nil pointer dereference
goroutine 52 [running]:
net/http.(*conn).serve.func1(0xc000202000)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1767 +0x139
panic(0x1609920, 0x1c083a0)
	/usr/local/Cellar/go/1.13.6/libexec/src/runtime/panic.go:679 +0x1b2
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3063 +0x72
database/sql.(*Rows).Close(0x0, 0xc0001332f0, 0x163b720)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3059 +0x33
imooc-product/repositories.(*ProductManager).SelectAll(0xc00032fc40, 0x0, 0x0, 0x0, 0x17c3c20, 0xc0000a6050)
	/Users/xxd/go/src/imooc-product/repositories/product_repository.go:138 +0x370
imooc-product/services.(*ProductService).GetAllProduct(0xc0001325b0, 0x1c3b300, 0x1d69658, 0xc0001cd5d0, 0x100dc36, 0xc0000a6000)
	/Users/xxd/go/src/imooc-product/services/product_service.go:31 +0x33
imooc-product/backend/web/controllers.(*ProductController).GetAll(0xc000402000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/xxd/go/src/imooc-product/backend/web/controllers/product_controller.go:17 +0x61
reflect.Value.call(0x162eac0, 0xc000402000, 0x613, 0x16bda2c, 0x4, 0x1c3a1e0, 0x0, 0x0, 0x4, 0xc0001b78a0, ...)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:460 +0x5f6
reflect.Value.Call(0x162eac0, 0xc000402000, 0x613, 0x1c3a1e0, 0x0, 0x0, 0x613, 0x800010004810800, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:321 +0xb4
github.com/kataras/iris/mvc.(*ControllerActivator).handlerOf.func2(0x17e5000, 0xc0001a6120)
	/Users/xxd/go/src/github.com/kataras/iris/mvc/controller.go:409 +0x5b2
github.com/kataras/iris/context.Do(0x17e5000, 0xc0001a6120, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:922 +0x81
github.com/kataras/iris/context.(*context).Do(0xc0001a6120, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:1094 +0x55
github.com/kataras/iris/core/router.(*routerHandler).HandleRequest(0xc0003e82a0, 0x17e5000, 0xc0001a6120)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/handler.go:227 +0x55c
github.com/kataras/iris/core/router.(*Router).BuildRouter.func1(0x17ced20, 0xc00020e000, 0xc000204000)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:84 +0x8f
github.com/kataras/iris/core/router.(*Router).ServeHTTP(0xc000151880, 0x17ced20, 0xc00020e000, 0xc000204000)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:161 +0x48
net/http.serverHandler.ServeHTTP(0xc0000fe8c0, 0x17ced20, 0xc00020e000, 0xc000204000)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc000202000, 0x17d0860, 0xc00019e000)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2928 +0x384
[HTTP Server] http: panic serving 127.0.0.1:50430: runtime error: invalid memory address or nil pointer dereference
goroutine 70 [running]:
net/http.(*conn).serve.func1(0xc000136fa0)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1767 +0x139
panic(0x1609920, 0x1c083a0)
	/usr/local/Cellar/go/1.13.6/libexec/src/runtime/panic.go:679 +0x1b2
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3063 +0x72
database/sql.(*Rows).Close(0x0, 0xc0001332f0, 0x163b720)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3059 +0x33
imooc-product/repositories.(*ProductManager).SelectAll(0xc00032fc40, 0x0, 0x0, 0x0, 0x17c3c20, 0xc0004fd950)
	/Users/xxd/go/src/imooc-product/repositories/product_repository.go:138 +0x370
imooc-product/services.(*ProductService).GetAllProduct(0xc0001325b0, 0x1c3b300, 0x0, 0xc0001d15d0, 0x100dc36, 0xc0004fd900)
	/Users/xxd/go/src/imooc-product/services/product_service.go:31 +0x33
imooc-product/backend/web/controllers.(*ProductController).GetAll(0xc0003e8840, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/xxd/go/src/imooc-product/backend/web/controllers/product_controller.go:17 +0x61
reflect.Value.call(0x162eac0, 0xc0003e8840, 0x613, 0x16bda2c, 0x4, 0x1c3a1e0, 0x0, 0x0, 0x4, 0xc0000538a0, ...)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:460 +0x5f6
reflect.Value.Call(0x162eac0, 0xc0003e8840, 0x613, 0x1c3a1e0, 0x0, 0x0, 0x613, 0x0, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:321 +0xb4
github.com/kataras/iris/mvc.(*ControllerActivator).handlerOf.func2(0x17e5000, 0xc0000c4750)
	/Users/xxd/go/src/github.com/kataras/iris/mvc/controller.go:409 +0x5b2
github.com/kataras/iris/context.Do(0x17e5000, 0xc0000c4750, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:922 +0x81
github.com/kataras/iris/context.(*context).Do(0xc0000c4750, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:1094 +0x55
github.com/kataras/iris/core/router.(*routerHandler).HandleRequest(0xc0003e82a0, 0x17e5000, 0xc0000c4750)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/handler.go:227 +0x55c
github.com/kataras/iris/core/router.(*Router).BuildRouter.func1(0x17ced20, 0xc0000feb60, 0xc000330c00)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:84 +0x8f
github.com/kataras/iris/core/router.(*Router).ServeHTTP(0xc000151880, 0x17ced20, 0xc0000feb60, 0xc000330c00)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:161 +0x48
net/http.serverHandler.ServeHTTP(0xc0000fe8c0, 0x17ced20, 0xc0000feb60, 0xc000330c00)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc000136fa0, 0x17d0860, 0xc00017ed80)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2928 +0x384
[HTTP Server] http: panic serving 127.0.0.1:50432: runtime error: invalid memory address or nil pointer dereference
goroutine 54 [running]:
net/http.(*conn).serve.func1(0xc0002020a0)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1767 +0x139
panic(0x1609920, 0x1c083a0)
	/usr/local/Cellar/go/1.13.6/libexec/src/runtime/panic.go:679 +0x1b2
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3063 +0x72
database/sql.(*Rows).Close(0x0, 0xc0001332f0, 0x163b720)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3059 +0x33
imooc-product/repositories.(*ProductManager).SelectAll(0xc00032fc40, 0x0, 0x0, 0x0, 0x17c3c20, 0xc0004a02d0)
	/Users/xxd/go/src/imooc-product/repositories/product_repository.go:138 +0x370
imooc-product/services.(*ProductService).GetAllProduct(0xc0001325b0, 0x1c3b300, 0x0, 0xc0001d35d0, 0x100dc36, 0xc0004a0280)
	/Users/xxd/go/src/imooc-product/services/product_service.go:31 +0x33
imooc-product/backend/web/controllers.(*ProductController).GetAll(0xc0003f60c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/xxd/go/src/imooc-product/backend/web/controllers/product_controller.go:17 +0x61
reflect.Value.call(0x162eac0, 0xc0003f60c0, 0x613, 0x16bda2c, 0x4, 0x1c3a1e0, 0x0, 0x0, 0x4, 0xc0001b78a0, ...)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:460 +0x5f6
reflect.Value.Call(0x162eac0, 0xc0003f60c0, 0x613, 0x1c3a1e0, 0x0, 0x0, 0x613, 0x800010004812200, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:321 +0xb4
github.com/kataras/iris/mvc.(*ControllerActivator).handlerOf.func2(0x17e5000, 0xc00023e090)
	/Users/xxd/go/src/github.com/kataras/iris/mvc/controller.go:409 +0x5b2
github.com/kataras/iris/context.Do(0x17e5000, 0xc00023e090, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:922 +0x81
github.com/kataras/iris/context.(*context).Do(0xc00023e090, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:1094 +0x55
github.com/kataras/iris/core/router.(*routerHandler).HandleRequest(0xc0003e82a0, 0x17e5000, 0xc00023e090)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/handler.go:227 +0x55c
github.com/kataras/iris/core/router.(*Router).BuildRouter.func1(0x17ced20, 0xc000242000, 0xc000204100)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:84 +0x8f
github.com/kataras/iris/core/router.(*Router).ServeHTTP(0xc000151880, 0x17ced20, 0xc000242000, 0xc000204100)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:161 +0x48
net/http.serverHandler.ServeHTTP(0xc0000fe8c0, 0x17ced20, 0xc000242000, 0xc000204100)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc0002020a0, 0x17d0860, 0xc00019e200)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2928 +0x384
[HTTP Server] http: panic serving 127.0.0.1:50436: runtime error: invalid memory address or nil pointer dereference
goroutine 25 [running]:
net/http.(*conn).serve.func1(0xc0001c2140)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1767 +0x139
panic(0x1609920, 0x1c083a0)
	/usr/local/Cellar/go/1.13.6/libexec/src/runtime/panic.go:679 +0x1b2
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3063 +0x72
database/sql.(*Rows).Close(0x0, 0xc0001332f0, 0x163b720)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3059 +0x33
imooc-product/repositories.(*ProductManager).SelectAll(0xc00032fc40, 0x0, 0x0, 0x0, 0x17c3c20, 0xc0004a03c0)
	/Users/xxd/go/src/imooc-product/repositories/product_repository.go:138 +0x370
imooc-product/services.(*ProductService).GetAllProduct(0xc0001325b0, 0x1c3b300, 0x0, 0xc0001d35d0, 0x100dc36, 0xc0004a0370)
	/Users/xxd/go/src/imooc-product/services/product_service.go:31 +0x33
imooc-product/backend/web/controllers.(*ProductController).GetAll(0xc0003f6160, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/xxd/go/src/imooc-product/backend/web/controllers/product_controller.go:17 +0x61
reflect.Value.call(0x162eac0, 0xc0003f6160, 0x613, 0x16bda2c, 0x4, 0x1c3a1e0, 0x0, 0x0, 0x4, 0xc0001b78a0, ...)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:460 +0x5f6
reflect.Value.Call(0x162eac0, 0xc0003f6160, 0x613, 0x1c3a1e0, 0x0, 0x0, 0x613, 0x0, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:321 +0xb4
github.com/kataras/iris/mvc.(*ControllerActivator).handlerOf.func2(0x17e5000, 0xc00023e1b0)
	/Users/xxd/go/src/github.com/kataras/iris/mvc/controller.go:409 +0x5b2
github.com/kataras/iris/context.Do(0x17e5000, 0xc00023e1b0, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:922 +0x81
github.com/kataras/iris/context.(*context).Do(0xc00023e1b0, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:1094 +0x55
github.com/kataras/iris/core/router.(*routerHandler).HandleRequest(0xc0003e82a0, 0x17e5000, 0xc00023e1b0)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/handler.go:227 +0x55c
github.com/kataras/iris/core/router.(*Router).BuildRouter.func1(0x17ced20, 0xc0002420e0, 0xc000156300)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:84 +0x8f
github.com/kataras/iris/core/router.(*Router).ServeHTTP(0xc000151880, 0x17ced20, 0xc0002420e0, 0xc000156300)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:161 +0x48
net/http.serverHandler.ServeHTTP(0xc0000fe8c0, 0x17ced20, 0xc0002420e0, 0xc000156300)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc0001c2140, 0x17d0860, 0xc000196500)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2928 +0x384
[HTTP Server] http: panic serving 127.0.0.1:50627: runtime error: invalid memory address or nil pointer dereference
goroutine 27 [running]:
net/http.(*conn).serve.func1(0xc0001c21e0)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1767 +0x139
panic(0x1609920, 0x1c083a0)
	/usr/local/Cellar/go/1.13.6/libexec/src/runtime/panic.go:679 +0x1b2
database/sql.(*Rows).close(0x0, 0x0, 0x0, 0x0, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3063 +0x72
database/sql.(*Rows).Close(0x0, 0xc0001332f0, 0x163b720)
	/usr/local/Cellar/go/1.13.6/libexec/src/database/sql/sql.go:3059 +0x33
imooc-product/repositories.(*ProductManager).SelectAll(0xc00032fc40, 0x0, 0x0, 0x0, 0x17c3c20, 0xc0004fd9f0)
	/Users/xxd/go/src/imooc-product/repositories/product_repository.go:138 +0x370
imooc-product/services.(*ProductService).GetAllProduct(0xc0001325b0, 0x1c3b300, 0x0, 0xc0001d35d0, 0x100dc36, 0xc0004a0460)
	/Users/xxd/go/src/imooc-product/services/product_service.go:31 +0x33
imooc-product/backend/web/controllers.(*ProductController).GetAll(0xc0003f6200, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/xxd/go/src/imooc-product/backend/web/controllers/product_controller.go:17 +0x61
reflect.Value.call(0x162eac0, 0xc0003f6200, 0x613, 0x16bda2c, 0x4, 0x1c3a1e0, 0x0, 0x0, 0x4, 0xc0001bb8a0, ...)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:460 +0x5f6
reflect.Value.Call(0x162eac0, 0xc0003f6200, 0x613, 0x1c3a1e0, 0x0, 0x0, 0x613, 0x0, 0x0)
	/usr/local/Cellar/go/1.13.6/libexec/src/reflect/value.go:321 +0xb4
github.com/kataras/iris/mvc.(*ControllerActivator).handlerOf.func2(0x17e5000, 0xc00023e2d0)
	/Users/xxd/go/src/github.com/kataras/iris/mvc/controller.go:409 +0x5b2
github.com/kataras/iris/context.Do(0x17e5000, 0xc00023e2d0, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:922 +0x81
github.com/kataras/iris/context.(*context).Do(0xc00023e2d0, 0xc0004e7fe0, 0x1, 0x1)
	/Users/xxd/go/src/github.com/kataras/iris/context/context.go:1094 +0x55
github.com/kataras/iris/core/router.(*routerHandler).HandleRequest(0xc0003e82a0, 0x17e5000, 0xc00023e2d0)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/handler.go:227 +0x55c
github.com/kataras/iris/core/router.(*Router).BuildRouter.func1(0x17ced20, 0xc0002421c0, 0xc000156500)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:84 +0x8f
github.com/kataras/iris/core/router.(*Router).ServeHTTP(0xc000151880, 0x17ced20, 0xc0002421c0, 0xc000156500)
	/Users/xxd/go/src/github.com/kataras/iris/core/router/router.go:161 +0x48
net/http.serverHandler.ServeHTTP(0xc0000fe8c0, 0x17ced20, 0xc0002421c0, 0xc000156500)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2802 +0xa4
net/http.(*conn).serve(0xc0001c21e0, 0x17d0860, 0xc000196800)
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:1890 +0x875
created by net/http.(*Server).Serve
	/usr/local/Cellar/go/1.13.6/libexec/src/net/http/server.go:2928 +0x384

文件也都引入:
图片描述
数据库表

CREATE TABLE `product` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `productName` varchar(255) DEFAULT NULL,
  `productNum` int(11) DEFAULT NULL,
  `productImage` varchar(255) DEFAULT NULL,
  `productUrl` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

product/add可以访问
图片描述

什么问题呢?谢谢

写回答

2回答

Cap

2020-03-11

product_repository.go:138 行用到的mysql相关实例有没有初始化?

0
1
慕粉慕粉1888
找到问题了 数据库端口错了,谢谢老师
2020-03-11
共1条回复

Cap

2020-03-11

下面错误信息有吗?复制出来

0
1
慕粉慕粉1888
上边编辑了,您看下,谢谢
2020-03-11
共1条回复

全流程开发 GO实战电商网站高并发秒杀系统

运用架构设计与系统化思维,从容应对不同流量等级的“秒杀”场景

1462 学习 · 443 问题

查看课程