Skip to content
This repository was archived by the owner on Apr 23, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions get_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,49 @@ First, create a `main.go` with
package main

import (
"fmt"
"net/http"
"github.com/qor/qor"
"github.com/qor/admin"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/qor/admin"
"net/http"
)

// Define a GORM-backend model
type User struct {
gorm.Model
Name string
gorm.Model
Name string
}

// Define another GORM-backend model
type Product struct {
gorm.Model
Name string
Description string
gorm.Model
Name string
Description string
}

func main() {
// Set up the database
DB, _ := gorm.Open("sqlite3", "demo.db")
DB.AutoMigrate(&User{}, &Product{})
// Set up the database
DB, _ := gorm.Open("sqlite3", "demo.db")
DB.AutoMigrate(&User{}, &Product{})

// Initalize
Admin := admin.New(&admin.AdminConfig{DB: DB})
// Initialize
Admin := admin.New(&admin.AdminConfig{DB: DB})

// Create resources from GORM-backend model
Admin.AddResource(&User{})
Admin.AddResource(&Product{})
// Create resources from GORM-backend model
Admin.AddResource(&User{})
Admin.AddResource(&Product{})

// Initalize an HTTP request multiplexer
mux := http.NewServeMux()
// Initialize an HTTP request multiplexer
mux := http.NewServeMux()

// Mount admin to the mux
Admin.MountTo("/admin", mux)
// Mount admin to the mux
Admin.MountTo("/admin", mux)

fmt.Println("Listening on: 9000")
http.ListenAndServe(":9000", mux)
fmt.Println("Listening on: 9000")
err := http.ListenAndServe(":9000", mux)
if err != nil {
panic("Error start serve")
}
}
```

Expand Down