Otfe/app.go

58 lines
1.4 KiB
Go
Raw Permalink Normal View History

2022-02-23 12:07:09 +00:00
package main
import (
"fmt"
"log"
"net/http"
c "git.1248.nz/1248/Otfe/controllers"
a "git.1248.nz/1248/Otfe/misc/auth"
"git.1248.nz/1248/Otfe/misc/helpers"
"github.com/husobee/vestigo"
)
func main() {
fmt.Println("Starting")
log.Fatal(http.ListenAndServe(":8080", router()))
}
func router() *vestigo.Router {
router := vestigo.NewRouter()
var static c.Static
router.Get("/", a.User(static.Home))
router.Get("/public/*", http.FileServer(
http.Dir(helpers.GetAssets())).ServeHTTP)
//User routes
var user c.User
router.Get("/user", c.User{}.Index)
router.Get("/user/:username", a.Perm(user.Show, user.ShowSelf,
"user.show"))
router.Get("/user/new", user.New)
router.Post("/user/new", user.Create)
router.Get("/user/:username/edit", user.Edit)
router.Post("/user/:username/edit", user.Update)
router.Post("/user/:username/delete", user.Delete)
router.Get("/register", user.New)
//Session routes
var session c.Session
router.Get("/login", session.New)
router.Post("/login", session.Create)
router.Post("/logout", session.Delete)
//Post routes
router.Get("/post", c.Post{}.Index)
router.Get("/user/:id", c.Post{}.Show)
router.Get("/post/new", c.Post{}.New)
router.Post("/post/new", c.Post{}.Create)
router.Get("/post/:id/edit", c.Post{}.Edit)
router.Post("/post/:id/edit", c.Post{}.Update)
router.Post("/post/:id/delete", c.Post{}.Delete)
return router
}