2021/02/12 17:17:56 Finish [GET] /admin Took 0.05ms
2021/02/12 17:17:56 http: panic serving 127.0.0.1:50746: runtime error: invalid memory address or nil pointer dereference
goroutine 65 [running]:
net/http.(*conn).serve.func1(0xc00076f040)
/usr/local/go/src/net/http/server.go:1801 +0x147
panic(0x10b91e0, 0x1a83350)
/usr/local/go/src/runtime/panic.go:975 +0x47a
html/template.(*Template).escape(0x0, 0x0, 0x0)
/usr/local/go/src/html/template/template.go:95 +0x3b
html/template.(*Template).Execute(0x0, 0x13c12e0, 0xc0001efb20, 0x122bc20, 0xc000523880, 0x1, 0xc0005413b0)
/usr/local/go/src/html/template/template.go:119 +0x2f
github.com/qor/admin.(*Context).Execute(0xc000523880, 0x123698a, 0x9, 0x0, 0x0)
/home/somersbmatthews/go/pkg/mod/github.com/qor/admin@v0.0.0-20210126080646-c154432d6e1b/context.go:227 +0x225
github.com/qor/admin.(*Controller).Dashboard(...)
/home/somersbmatthews/go/pkg/mod/github.com/qor/admin@v0.0.0-20210126080646-c154432d6e1b/controller.go:28
github.com/qor/admin.(*Admin).NewServeMux.func2(0xc000523880, 0xc000b90420)
/home/somersbmatthews/go/pkg/mod/github.com/qor/admin@v0.0.0-20210126080646-c154432d6e1b/route.go:176 +0x1ea
github.com/qor/admin.Middleware.Next(...)
/home/somersbmatthews/go/pkg/mod/github.com/qor/admin@v0.0.0-20210126080646-c154432d6e1b/route.go:37
github.com/qor/admin.(*Admin).NewServeMux.func1(0xc000523880, 0xc000b90400)
/home/somersbmatthews/go/pkg/mod/github.com/qor/admin@v0.0.0-20210126080646-c154432d6e1b/route.go:166 +0x117
github.com/qor/admin.Middleware.Next(...)
/home/somersbmatthews/go/pkg/mod/github.com/qor/admin@v0.0.0-20210126080646-c154432d6e1b/route.go:37
github.com/qor/admin.Admin.registerCompositePrimaryKeyCallback.func1(0xc000523880, 0xc000a0b0a0)
/home/somersbmatthews/go/pkg/mod/github.com/qor/admin@v0.0.0-20210126080646-c154432d6e1b/composite_primary_key_callback.go:27 +0x25c
github.com/qor/admin.(*serveMux).ServeHTTP(0xc0007961c0, 0x13d75c0, 0xc0001efb20, 0xc0003e3000)
/home/somersbmatthews/go/pkg/mod/github.com/qor/admin@v0.0.0-20210126080646-c154432d6e1b/route.go:267 +0x54e
net/http.(*ServeMux).ServeHTTP(0xc000776480, 0x13d75c0, 0xc0001efb20, 0xc0003e3000)
/usr/local/go/src/net/http/server.go:2417 +0x1ad
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000bac000, 0x13d75c0, 0xc0001efb20, 0xc0003e2e00)
/home/somersbmatthews/go/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0xd3
net/http.serverHandler.ServeHTTP(0xc000a340e0, 0x13d75c0, 0xc0001efb20, 0xc0003e2e00)
/usr/local/go/src/net/http/server.go:2843 +0xa3
net/http.(*conn).serve(0xc00076f040, 0x13e0980, 0xc0003bc880)
/usr/local/go/src/net/http/server.go:1925 +0x8ad
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2969 +0x36c
以上是我在尝试 GET 方法时遇到的 go-swagger 服务器生成的错误,它使用 chrome 浏览器请求 /admin 路由,该路由指向 qor 仪表板。我在 main.go 中使用 gorilla/mux 实现了 qor 仪表板路由处理,如下所示:
Admin := dashboard.SetupAdmin() // I made a dashboard package that sets up the qor dashboard config
adminMux := http.NewServeMux()
Admin.MountTo("/admin", adminMux)
r := mux.NewRouter()
r.PathPrefix("/admin").Handler(adminMux)
r.PathPrefix("/").Handler(api.Serve(nil))
http.Handle("/", r)
srv := &http.Server{
Handler: r,
Addr: "127.0.0.1:8080",
// Good practice: enforce timeouts for servers you create!
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,
}
log.Fatal(srv.ListenAndServe())
我也试过用 vanilla net/http 替换上面的代码:
Admin := dashboard.SetupAdmin()
mux := http.NewServeMux()
Admin.MountTo("/admin", mux)
mux.Handle("/", api.Serve(nil))
http.ListenAndServe(":8080", mux)
但我仍然遇到与本文顶部相同的错误。
我已经删除并保留了相同的 qor 仪表板管理代码并运行服务器并调用其他路由连接、插入和删除附加的 postgres 数据库中的内容,这些路由工作得很好。
我觉得我错过了一些关于路由的小东西,但我已经分叉了 qor 仪表板项目,并且如果他们需要修复或需要更改以使用 go-swagger 生成的服务器,我愿意修复它们。我只是不知道从哪里开始。
也许该Admin.MountTo("/admin", mux)
功能无法正常工作?
在 /admin 路由上调用 GET 方法会导致本文顶部的错误。
以下是关于集成的 qor 仪表板文档:https ://doc.getqor.com/admin/integration.html
以下是自定义服务器上的 go-swagger 文档:https ://goswagger.io/tutorial/custom-server.html
任何帮助表示赞赏。:)