refactor: index page route separated

This commit is contained in:
efim
2023-11-05 05:00:01 +00:00
parent 83c634c2b9
commit 648d3dff80
4 changed files with 52 additions and 13 deletions

37
routes/index_page.go Normal file
View File

@@ -0,0 +1,37 @@
package routes
import (
"embed"
"fmt"
"html/template"
"log"
"net/http"
"sunshine.industries/some-automoderation/rooms"
"sunshine.industries/some-automoderation/sessions"
)
func indexPageRoute(
templateFs *embed.FS,
sessionSM sessions.SessionManagement,
roomsM rooms.RoomManager,
) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var templFile = "templates/index.gohtml"
session := getContextSession(r.Context())
data := struct {
SessionStringToken string
SomeString string
SessionToken sessions.SessionData
}{
fmt.Sprintf("%+v", session),
"hello!",
session,
}
tmpl := template.Must(template.ParseFS(templateFs, templFile))
err := tmpl.Execute(w, data)
if err != nil {
log.Printf("my error in executing template, huh\n %s", err)
}
})
}