package main import ( "log" "net/http" "wyo.town/netzah/models" "wyo.town/netzah/handlers" "wyo.town/netzah/session" "wyo.town/netzah/middleware" "github.com/gorilla/mux" "gorm.io/driver/postgres" "gorm.io/gorm" ) func init() { dsn := "host=localhost user=_postgresql password=postGRES dbname=netzah port=5432 sslmode=disable TimeZone=US/Mountain client_encoding=UTF8" db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) if err != nil { panic("failed to connect database") } db.AutoMigrate(&models.Blog{}) } func main() { session.Init() // 2) Router + attach SCS middleware correctly r := mux.NewRouter() r.Use(session.Manager.LoadAndSave) // 3) Routes r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) _, _ = w.Write([]byte("Hello, World!")) }) // Blog endpoints r.HandleFunc("/blogs", handlers.CreateBlog).Methods(http.MethodGet) r.HandleFunc("/blogs", handlers.StoreBlog).Methods(http.MethodPost) r.HandleFunc("/blogs/{id}", handlers.GetBlog).Methods(http.MethodGet) r.HandleFunc("/login", handlers.LoginGET) r.HandleFunc("/login/submit", handlers.LoginPOST) // Logout (POST is recommended; allow GET only if you must) r.HandleFunc("/logout", handlers.LogoutPOST) // r.HandleFunc("/blogs/{id}", handlers.UpdateBlog).Methods(http.MethodPut) // r.HandleFunc("/blogs/{id}", handlers.DeleteBlog).Methods(http.MethodDelete) // Example protected route (SCS must already be on the chain) r.Handle("/whoami", middleware.RequireAuth(http.HandlerFunc(handlers.Dashboard))) // 4) Start the server using the router you wrapped log.Println("Starting server on :8090") srv := &http.Server{ Addr: ":8090", Handler: r, } log.Fatal(srv.ListenAndServe()) }