hasID middleware validates the :id param in the URL and sets its int value in the context.
(next echo.HandlerFunc)
| 380 | |
| 381 | // hasID middleware validates the :id param in the URL and sets its int value in the context. |
| 382 | func hasID(next echo.HandlerFunc) echo.HandlerFunc { |
| 383 | return func(c echo.Context) error { |
| 384 | id, _ := strconv.Atoi(c.Param("id")) |
| 385 | if id < 1 { |
| 386 | return echo.NewHTTPError(http.StatusBadRequest, "invalid ID") |
| 387 | } |
| 388 | |
| 389 | c.Set("id", id) |
| 390 | return next(c) |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | // hasSub middleware checks if a subscriber exists given the UUID |
| 395 | // param in a request. |