package main import ( "github.com/qleelulu/goku" "github.com/qleelulu/goku/examples" ) func main() { app := goku.NewApp() app.HandleFunc("GET", "/users/:id", func(ctx *goku.HttpContext) goku.ActionResul { user := getUserById(ctx.Param("id")) jsonBytes, _ := goku.Json.Marshal(user) return goku.Json(jsonBytes) }) app.RunOnAddr(":8080") }
package main import ( "github.com/qleelulu/goku" "github.com/qleelulu/goku/examples" ) type User struct { Id int `json:"id"` Name string `json:"name"` Email string `json:"email"` } func main() { app := goku.NewApp() app.HandleFunc("POST", "/users", func(ctx *goku.HttpContext) goku.ActionResult { var user User ctx.Json(&user) saveUser(user) return goku.Text("User saved") }) app.RunOnAddr(":8080") }In this example, when a POST request is made to "/users", the JSON data in the request body is deserialized into a User struct and saved to the database.