Last active
September 7, 2019 07:21
-
-
Save WoolWarrior/2bd7ffe68d1ddefa2862bbd4723ab535 to your computer and use it in GitHub Desktop.
qor-admin naive implementation - sqlite3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"github.com/qor/qor" | |
"github.com/qor/admin" | |
"github.com/jinzhu/gorm" | |
_ "github.com/jinzhu/gorm/dialects/sqlite" | |
) | |
// 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{}) | |
// Initalize | |
Admin := admin.New(&admin.AdminConfig{DB: DB}) | |
// Create resources from GORM-backend model | |
Admin.AddResource(&User{}) | |
Admin.AddResource(&Product{}) | |
// Initalize an HTTP request multiplexer | |
mux := http.NewServeMux() | |
// Mount admin to the mux | |
Admin.MountTo("/admin", mux) | |
fmt.Println("Listening on: 9000") | |
http.ListenAndServe(":9000", mux) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment