Begin refactoring structure

This commit is contained in:
Maximilian
2024-07-01 21:19:48 -05:00
parent 86ff949eae
commit ce85d6b77b
23 changed files with 55 additions and 58 deletions

33
app/routes/get.go Normal file
View File

@ -0,0 +1,33 @@
package routes
import (
"GoWeb/app"
"GoWeb/app/controllers"
"io/fs"
"log/slog"
"net/http"
)
// Get defines all project get routes
func Get(app *app.Deps) {
// Get controller struct initialize
getController := controllers.Get{
App: app,
}
// Serve static files
staticFS, err := fs.Sub(app.Res, "static")
if err != nil {
slog.Error(err.Error())
return
}
staticHandler := http.FileServer(http.FS(staticFS))
http.Handle("/static/", http.StripPrefix("/static/", staticHandler))
slog.Info("serving static files from embedded file system /static")
// Pages
http.HandleFunc("/", getController.ShowHome)
http.HandleFunc("/login", getController.ShowLogin)
http.HandleFunc("/register", getController.ShowRegister)
http.HandleFunc("/logout", getController.Logout)
}

20
app/routes/post.go Normal file
View File

@ -0,0 +1,20 @@
package routes
import (
"GoWeb/app"
"GoWeb/app/controllers"
"GoWeb/app/middleware"
"net/http"
)
// Post defines all project post routes
func Post(app *app.Deps) {
// Post controller struct initialize
postController := controllers.Post{
App: app,
}
// User authentication
http.HandleFunc("/register-handle", middleware.Csrf(postController.Register))
http.HandleFunc("/login-handle", middleware.Csrf(postController.Login))
}