-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (51 loc) · 1.26 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// based on https://doc.getqor.com/get_started.html
package main
import (
"fmt"
"log"
"net/http"
"path/filepath"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/qor/admin"
"github.com/qor/assetfs"
"github.com/qor/qor/utils"
_ "github.com/sergolius/qor_bindatafs_example/config/bindatafs"
)
// Define a GORM-backend model
type User struct {
gorm.Model
Name string
}
// Define another GORM-backend model
type Product struct {
gorm.Model
Name string
Description string
}
func main() {
// Set up the database
DB, _ := gorm.Open("sqlite3", "demo.db")
DB.AutoMigrate(&User{}, &Product{})
// Initialize AssetFS
AssetFS := assetfs.AssetFS().NameSpace("admin")
// Register custom paths to manually saved views
AssetFS.RegisterPath(filepath.Join(utils.AppRoot, "qor/admin/views"))
// Initialize Admin
Admin := admin.New(&admin.AdminConfig{
DB: DB,
AssetFS: AssetFS,
})
// Create resources from GORM-backend model
Admin.AddResource(&User{})
Admin.AddResource(&Product{})
// Initialize an HTTP request multiplexer
mux := http.NewServeMux()
// Mount admin to the mux
Admin.MountTo("/admin", mux)
fmt.Println("Listening on: 8080")
err := http.ListenAndServe(":8080", mux)
if err != nil {
log.Fatalln(err)
}
}