JSON helper to give end-user the ability to put indention chars or filtering the response, you can do that, optionally. If you'd like to see that function inside the Iris' Context itself raise a [Feature Request] issue and link this example.
(ctx iris.Context, resp interface{})
| 142 | // JSON helper to give end-user the ability to put indention chars or filtering the response, you can do that, optionally. |
| 143 | // If you'd like to see that function inside the Iris' Context itself raise a [Feature Request] issue and link this example. |
| 144 | func sendJSON(ctx iris.Context, resp interface{}) (err error) { |
| 145 | indent := ctx.URLParamDefault("indent", " ") |
| 146 | // i.e [?Name == 'John Doe'].Age # to output the [age] of a user which his name is "John Doe". |
| 147 | if query := ctx.URLParam("query"); query != "" && query != "[]" { |
| 148 | resp, err = jmespath.Search(query, resp) |
| 149 | if err != nil { |
| 150 | return |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | err = ctx.JSON(resp, iris.JSON{Indent: indent, UnescapeHTML: true}) |
| 155 | return err |
| 156 | } |
no test coverage detected
searching dependent graphs…