Begin refactoring structure
This commit is contained in:
33
app/routes/get.go
Normal file
33
app/routes/get.go
Normal 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
20
app/routes/post.go
Normal 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))
|
||||
}
|
Reference in New Issue
Block a user