GetByID fetches a single record from the database and sends it to the client. Method: GET.
(ctx iris.Context)
| 28 | // GetByID fetches a single record from the database and sends it to the client. |
| 29 | // Method: GET. |
| 30 | func (h *ProductHandler) GetByID(ctx iris.Context) { |
| 31 | id := ctx.Params().GetString("id") |
| 32 | |
| 33 | var product []byte |
| 34 | err := h.cache.GetByID(ctx.Request().Context(), id, &product) |
| 35 | if err != nil { |
| 36 | if err == sql.ErrNoRows { |
| 37 | writeEntityNotFound(ctx) |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | debugf("ProductHandler.GetByID(id=%v): %v", id, err) |
| 42 | writeInternalServerError(ctx) |
| 43 | return |
| 44 | } |
| 45 | |
| 46 | ctx.ContentType("application/json") |
| 47 | ctx.Write(product) |
| 48 | |
| 49 | // ^ Could use our simple `noCache` or implement a Cache-Control (see kataras/iris/cache for that) |
| 50 | // but let's keep it simple. |
| 51 | } |
| 52 | |
| 53 | // List lists a set of records from the database. |
| 54 | // Method: GET. |
nothing calls this directly
no test coverage detected