MCPcopy Create free account
hub / github.com/kataras/iris / GetByID

Method GetByID

_examples/database/mysql/api/product_handler.go:30–51  ·  view source on GitHub ↗

GetByID fetches a single record from the database and sends it to the client. Method: GET.

(ctx iris.Context)

Source from the content-addressed store, hash-verified

28// GetByID fetches a single record from the database and sends it to the client.
29// Method: GET.
30func (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.

Callers

nothing calls this directly

Calls 10

writeEntityNotFoundFunction · 0.85
debugfFunction · 0.85
writeInternalServerErrorFunction · 0.85
ParamsMethod · 0.80
ContextMethod · 0.80
RequestMethod · 0.80
GetByIDMethod · 0.65
GetStringMethod · 0.45
ContentTypeMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected