50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"lishwist/auth"
|
|
"lishwist/context"
|
|
"lishwist/db"
|
|
"lishwist/templates"
|
|
)
|
|
|
|
func main() {
|
|
err := db.Open()
|
|
if err != nil {
|
|
log.Fatalf("Failed to open DB: %s\n", err)
|
|
}
|
|
err = db.Init()
|
|
if err != nil {
|
|
log.Fatalf("Failed to init DB: %s\n", err)
|
|
}
|
|
|
|
publicMux := http.NewServeMux()
|
|
protectedMux := http.NewServeMux()
|
|
|
|
authMiddleware := auth.NewAuthMiddleware(protectedMux, publicMux)
|
|
|
|
ctx := context.Context{
|
|
Auth: authMiddleware,
|
|
}
|
|
|
|
publicMux.HandleFunc("GET /register", templates.Register)
|
|
publicMux.HandleFunc("POST /register", authMiddleware.RegisterPost)
|
|
publicMux.HandleFunc("GET /", templates.Login)
|
|
publicMux.HandleFunc("POST /", authMiddleware.LoginPost)
|
|
|
|
protectedMux.HandleFunc("GET /", ctx.Home)
|
|
protectedMux.HandleFunc("GET /{username}", ctx.ViewForeignWishlist)
|
|
protectedMux.HandleFunc("POST /wishlist/add", ctx.WishlistAdd)
|
|
protectedMux.HandleFunc("POST /wishlist/delete", ctx.WishlistDelete)
|
|
protectedMux.HandleFunc("POST /logout", authMiddleware.LogoutPost)
|
|
|
|
// TODO: Remove me
|
|
protectedMux.HandleFunc("GET /logout", authMiddleware.LogoutPost)
|
|
|
|
http.Handle("/", authMiddleware)
|
|
|
|
http.ListenAndServe(":4000", nil)
|
|
}
|