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
Above is the go-swagger server generated error I'm getting when trying to GET method request the /admin route with chrome browser, which is to the qor dashboard. I implemented the qor dashboard route handling with gorilla/mux like this in main.go:
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())
I have also tried replacing the above code with vanilla net/http:
Admin := dashboard.SetupAdmin()
mux := http.NewServeMux()
Admin.MountTo("/admin", mux)
mux.Handle("/", api.Serve(nil))
http.ListenAndServe(":8080", mux)
but I still get the same error as at the top of this post.
I have removed and kept the same the qor dashboard admin code and run the server and called the other routes that connect, insert, and delete things from the attached postgres database, and those routes work just fine.
I have the feeling I am missing something small about routing, but I have forked the qor dashboard projects and am willing to fix them if they need fixing or need alteration to work with a go-swagger generated server. I am just not sure where to start.
Maybe the Admin.MountTo("/admin", mux)
function isn't working correctly?
Calling the GET method on the /admin route causes the error at the top of this post.
Here are the qor dashboard docs on integration: https://doc.getqor.com/admin/integration.html
Here are the go-swagger docs on custom server: https://goswagger.io/tutorial/custom-server.html
Any help is appreciated. :)