64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/gob"
|
|
"log"
|
|
"net/http"
|
|
|
|
"lishwist/api"
|
|
"lishwist/db"
|
|
"lishwist/env"
|
|
"lishwist/router"
|
|
"lishwist/routing"
|
|
)
|
|
|
|
func main() {
|
|
gob.Register(&api.RegisterProps{})
|
|
gob.Register(&routing.LoginProps{})
|
|
|
|
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)
|
|
}
|
|
|
|
store, err := db.NewSessionStore()
|
|
if err != nil {
|
|
log.Fatalf("Failed to ")
|
|
}
|
|
store.Options.MaxAge = 86_400
|
|
store.Options.Secure = !env.InDev
|
|
store.Options.HttpOnly = true
|
|
|
|
r := router.New(store)
|
|
|
|
route := routing.NewContext(store)
|
|
|
|
r.Html.Public.HandleFunc("GET /register", route.Register)
|
|
r.Html.Public.HandleFunc("POST /register", route.RegisterPost)
|
|
r.Html.Public.HandleFunc("GET /", route.Login)
|
|
r.Html.Public.HandleFunc("POST /", route.LoginPost)
|
|
r.Html.Public.HandleFunc("GET /list/{userReference}", route.PublicWishlist)
|
|
r.Html.Public.HandleFunc("GET /group/{groupReference}", route.PublicGroupPage)
|
|
|
|
r.Html.Private.HandleFunc("GET /{$}", route.Home)
|
|
r.Html.Private.HandleFunc("POST /{$}", route.HomePost)
|
|
r.Html.Private.HandleFunc("GET /list/{userReference}", route.ForeignWishlist)
|
|
r.Html.Private.HandleFunc("POST /list/{userReference}", route.ForeignWishlistPost)
|
|
r.Html.Private.HandleFunc("GET /group/{groupReference}", route.GroupPage)
|
|
r.Html.Private.HandleFunc("POST /logout", route.LogoutPost)
|
|
|
|
r.Json.Public.HandleFunc("POST /register", route.RegisterPostJson)
|
|
|
|
http.Handle("/", r)
|
|
|
|
log.Printf("Running at http://127.0.0.1:%s\n", env.ServePort)
|
|
err = http.ListenAndServe(":"+env.ServePort, nil)
|
|
if err != nil {
|
|
log.Fatalln("Failed to listen and server:", err)
|
|
}
|
|
}
|