forked from qor/qor-example
/
main.go
42 lines (32 loc) · 971 Bytes
/
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
package main
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/qor/qor-example/app/controllers"
. "github.com/qor/qor-example/app/resources"
)
func main() {
mux := http.NewServeMux()
Admin.MountTo("/admin", mux)
// frontend routes
router := gin.Default()
router.LoadHTMLGlob("templates/*")
// serve static files
router.StaticFS("/system/", http.Dir("public/system"))
router.StaticFS("/assets/", http.Dir("public/assets"))
// books
bookRoutes := router.Group("/books")
{
// listing
bookRoutes.GET("", controllers.ListBooksHandler)
bookRoutes.GET("/", controllers.ListBooksHandler) // really? i need both of those?...
// single book - product page
bookRoutes.GET("/:id", controllers.ViewBookHandler)
}
mux.Handle("/", router)
// handle login and logout of users
mux.HandleFunc("/login", controllers.LoginHandler)
mux.HandleFunc("/logout", controllers.LogoutHandler)
// start the server
http.ListenAndServe(":9000", mux)
}