1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 18:07:01 +00:00

add x/errors.Handler, CreateHandler, NoContentHandler, NoContenetOrNotModifiedHandler and ListHandler ready-to-use handlers for service method calls to Iris Handler

This commit is contained in:
Gerasimos (Makis) Maropoulos
2024-01-09 11:11:53 +02:00
parent 7024f61a62
commit ad75479541
7 changed files with 161 additions and 18 deletions

View File

@@ -14,10 +14,10 @@ func main() {
app := iris.New()
service := new(myService)
app.Post("/", createHandler(service))
app.Get("/", listAllHandler(service))
app.Post("/page", listHandler(service))
app.Delete("/{id:string}", deleteHandler(service))
app.Post("/", createHandler(service)) // OR: errors.CreateHandler(service.Create)
app.Get("/", listAllHandler(service)) // OR errors.Handler(service.ListAll, errors.Value(ListRequest{}))
app.Post("/page", listHandler(service)) // OR: errors.ListHandler(service.ListPaginated)
app.Delete("/{id:string}", deleteHandler(service)) // OR: errors.NoContentOrNotModifiedHandler(service.DeleteWithFeedback, errors.PathParam[string]("id"))
app.Listen(":8080")
}
@@ -59,9 +59,9 @@ func deleteHandler(service *myService) iris.Handler {
return func(ctx iris.Context) {
id := ctx.Params().Get("id")
// What it does?
// 1. Calls the service.Delete function with the given input parameter.
// 2. If the service.Delete returns an error, it sends an appropriate error response to the client.
// 3.If the service.Delete doesn't return an error then it sets the status code to 204 (No Content) and
// 1. Calls the service.DeleteWithFeedback function with the given input parameter.
// 2. If the service.DeleteWithFeedback returns an error, it sends an appropriate error response to the client.
// 3.If the service.DeleteWithFeedback doesn't return an error then it sets the status code to 204 (No Content) and
// sends the response as a JSON payload to the client.
// errors.NoContent(ctx, service.Delete, id)
// OR: