package handler
import "github.com/go-mizu/mizu"
type Post struct {
ID string
Title string
Summary string
Content string
Date string
}
var posts = []Post{
{
ID: "1",
Title: "Getting Started with Mizu",
Summary: "Learn how to build web apps with Mizu",
Content: "Mizu is a lightweight web framework for Go...",
Date: "January 15, 2024",
},
{
ID: "2",
Title: "Building APIs",
Summary: "Create REST APIs quickly",
Content: "Building APIs with Mizu is straightforward...",
Date: "January 10, 2024",
},
}
func PostList() mizu.Handler {
return func(c *mizu.Ctx) error {
return c.Render("pages/posts", map[string]any{
"Title": "Blog Posts",
"Posts": posts,
})
}
}
func PostShow() mizu.Handler {
return func(c *mizu.Ctx) error {
id := c.Param("id")
for _, p := range posts {
if p.ID == id {
return c.Render("pages/post", map[string]any{
"Title": p.Title,
"Post": p,
})
}
}
return c.Text(404, "Post not found")
}
}