admin
admin copied to clipboard
quickstart example not workin
I've created a main.go following instructions at README but I get this error when accesing localhost:9000/admin:
2019/09/29 19:44:18 http: panic serving 192.168.33.1:51099: runtime error: invalid memory address or nil pointer dereference goroutine 29 [running]: net/http.(*conn).serve.func1(0xc0000e1400) /usr/lib/go-1.13/src/net/http/server.go:1767 +0x139 panic(0xa23c00, 0x1129020) /usr/lib/go-1.13/src/runtime/panic.go:679 +0x1b2 html/template.(*Template).escape(0x0, 0x0, 0x0) /usr/lib/go-1.13/src/html/template/template.go:95 +0x42 html/template.(*Template).Execute(0x0, 0xba9580, 0xc0002a29a0, 0xab4700, 0xc0000f4af0, 0x1, 0xc0000224b0) /usr/lib/go-1.13/src/html/template/template.go:119 +0x2f github.com/qor/admin.(*Context).Execute(0xc0000f4af0, 0xabc7d8, 0x9, 0x0, 0x0) /home/vagrant/go/src/github.com/qor/admin/context.go:227 +0x22c github.com/qor/admin.(*Controller).Dashboard(...) /home/vagrant/go/src/github.com/qor/admin/controller.go:28 github.com/qor/admin.(*Admin).NewServeMux.func2(0xc0000f4af0, 0xc000424f40) /home/vagrant/go/src/github.com/qor/admin/route.go:176 +0x1e6 github.com/qor/admin.Middleware.Next(...) /home/vagrant/go/src/github.com/qor/admin/route.go:37 github.com/qor/admin.(*Admin).NewServeMux.func1(0xc0000f4af0, 0xc000424f20) /home/vagrant/go/src/github.com/qor/admin/route.go:166 +0x115 github.com/qor/admin.Middleware.Next(...) /home/vagrant/go/src/github.com/qor/admin/route.go:37 github.com/qor/admin.Admin.registerCompositePrimaryKeyCallback.func1(0xc0000f4af0, 0xc0003f3dc0) /home/vagrant/go/src/github.com/qor/admin/composite_primary_key_callback.go:27 +0x24d github.com/qor/admin.(*serveMux).ServeHTTP(0xc0003f47a0, 0xbb3680, 0xc0002a29a0, 0xc00016c700) /home/vagrant/go/src/github.com/qor/admin/route.go:267 +0x559 net/http.(*ServeMux).ServeHTTP(0xc000397cc0, 0xbb3680, 0xc0002a29a0, 0xc00016c700) /usr/lib/go-1.13/src/net/http/server.go:2387 +0x1bd net/http.serverHandler.ServeHTTP(0xc0002a2620, 0xbb3680, 0xc0002a29a0, 0xc00016c700) /usr/lib/go-1.13/src/net/http/server.go:2802 +0xa4 net/http.(*conn).serve(0xc0000e1400, 0xbb52c0, 0xc00005e900) /usr/lib/go-1.13/src/net/http/server.go:1890 +0x875 created by net/http.(*Server).Serve /usr/lib/go-1.13/src/net/http/server.go:2927 +0x38e
this is my main.go code:
`package main
import ( "fmt" "net/http" "github.com/jinzhu/gorm" _ "github.com/mattn/go-sqlite3" //"github.com/qor/qor" "github.com/qor/admin" )
// Create a GORM-backend model type User struct { gorm.Model Name string }
// Create another GORM-backend model type Product struct { gorm.Model Name string Description string }
func main() { DB, _ := gorm.Open("sqlite3", "demo.db") DB.AutoMigrate(&User{}, &Product{})
// Initalize Admin := admin.New(&admin.AdminConfig{DB: DB})
// Allow to use Admin to manage User, Product Admin.AddResource(&User{}) Admin.AddResource(&Product{})
// initalize an HTTP request multiplexer mux := http.NewServeMux()
// Mount admin interface to mux Admin.MountTo("/admin", mux)
fmt.Println("Listening on: 9000") http.ListenAndServe(":9000", mux) }`
Same issue.
if gomodule is on, you must download admin templates via this tool.
https://github.com/nomad-software/vend
@arojoal qor was written before go mod ...
copy all template files in https://github.com/qor/admin/tree/master/views/ to app/views/qor/
a command like this should work
mkdir -p app/views/qor
cp -r ~/go/pkg/mod/github.com/qor/[email protected]/views/* app/views/qor/
or use bindatafs
@arojoal If you're using dep
then make sure you add the following to your prune
directive:
[prune]
go-tests = true
unused-packages = true
[[prune.project]]
name = "github.com/qor/admin"
unused-packages = false
This will ensure dep
doesn't remove the views folder.