package main
import (
"log"
"net/http"
"time"
"github.com/go-mizu/mizu"
)
// Welcome handler returning JSON
func welcome(c *mizu.Ctx) error {
data := map[string]string{
"message": "Welcome to Mizu JSON API",
}
return c.JSON(http.StatusOK, data)
}
// Current time handler
func currentTime(c *mizu.Ctx) error {
data := map[string]any{
"time": time.Now().Format(time.RFC3339),
"status": "ok",
}
return c.JSON(http.StatusOK, data)
}
// User info handler
func userInfo(c *mizu.Ctx) error {
user := struct {
Name string `json:"name"`
Email string `json:"email"`
}{
Name: "Alice",
Email: "alice@example.com",
}
return c.JSON(http.StatusOK, user)
}
func main() {
app := mizu.New()
app.Get("/", welcome)
app.Get("/time", currentTime)
app.Get("/user", userInfo)
if err := app.Listen(":8080"); err != nil {
log.Fatal(err)
}
}