2022-10-20 16:59:33 +00:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"GoWeb/app"
|
|
|
|
"GoWeb/controllers"
|
2023-03-06 18:43:54 +00:00
|
|
|
"io/fs"
|
2023-09-03 20:45:12 +00:00
|
|
|
"log/slog"
|
2022-10-20 16:59:33 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2023-08-03 17:09:40 +00:00
|
|
|
// Get defines all project get routes
|
|
|
|
func Get(app *app.App) {
|
2022-10-20 16:59:33 +00:00
|
|
|
// Get controller struct initialize
|
2023-08-03 17:09:40 +00:00
|
|
|
getController := controllers.Get{
|
2022-10-20 16:59:33 +00:00
|
|
|
App: app,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serve static files
|
2023-03-06 18:43:54 +00:00
|
|
|
staticFS, err := fs.Sub(app.Res, "static")
|
|
|
|
if err != nil {
|
2023-09-03 20:45:12 +00:00
|
|
|
slog.Error(err.Error())
|
2023-03-06 18:43:54 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
staticHandler := http.FileServer(http.FS(staticFS))
|
|
|
|
http.Handle("/static/", http.StripPrefix("/static/", staticHandler))
|
2023-09-03 20:56:35 +00:00
|
|
|
slog.Info("serving static files from embedded file system /static")
|
2022-10-20 16:59:33 +00:00
|
|
|
|
|
|
|
// Pages
|
|
|
|
http.HandleFunc("/", getController.ShowHome)
|
2022-11-01 16:23:44 +00:00
|
|
|
http.HandleFunc("/login", getController.ShowLogin)
|
2022-10-20 16:59:33 +00:00
|
|
|
http.HandleFunc("/register", getController.ShowRegister)
|
2022-11-01 16:23:44 +00:00
|
|
|
http.HandleFunc("/logout", getController.Logout)
|
2022-10-20 16:59:33 +00:00
|
|
|
}
|