48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
|
|
"lishwist/auth"
|
|
"lishwist/context"
|
|
"lishwist/db"
|
|
"lishwist/env"
|
|
"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 /", authMiddleware.Login)
|
|
publicMux.HandleFunc("POST /", authMiddleware.LoginPost)
|
|
|
|
protectedMux.HandleFunc("GET /{$}", ctx.Home)
|
|
protectedMux.HandleFunc("POST /{$}", ctx.HomePost)
|
|
protectedMux.HandleFunc("GET /list/{userReference}", ctx.ForeignWishlist)
|
|
protectedMux.HandleFunc("POST /list/{userReference}", ctx.ForeignWishlistPost)
|
|
protectedMux.HandleFunc("POST /logout", authMiddleware.LogoutPost)
|
|
|
|
http.Handle("/", authMiddleware)
|
|
|
|
http.ListenAndServe(":"+env.ServePort, nil)
|
|
}
|