40 lines
912 B
Go
40 lines
912 B
Go
package routes
|
|
|
|
import (
|
|
"dk/internal/middleware"
|
|
"dk/internal/router"
|
|
"dk/internal/template"
|
|
"dk/internal/template/components"
|
|
"fmt"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
)
|
|
|
|
func RegisterTownRoutes(r *router.Router) {
|
|
group := r.Group("/town")
|
|
group.Use(middleware.RequireAuth())
|
|
group.Use(middleware.RequireTown())
|
|
|
|
group.Get("/", showTown)
|
|
}
|
|
|
|
func showTown(ctx router.Ctx, _ []string) {
|
|
tmpl, err := template.Cache.Load("town/town.html")
|
|
if err != nil {
|
|
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
|
fmt.Fprintf(ctx, "Template error: %v", err)
|
|
return
|
|
}
|
|
|
|
content := tmpl.RenderNamed(map[string]any{
|
|
"town": ctx.UserValue("town"),
|
|
})
|
|
|
|
pageData := components.NewPageData("Town - Dragon Knight", content)
|
|
if err := components.RenderPage(ctx, pageData, nil); err != nil {
|
|
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
|
fmt.Fprintf(ctx, "Template error: %v", err)
|
|
return
|
|
}
|
|
}
|