Context is the most important part of gin. It allows us to pass variables between middleware, manage the flow, validate the JSON of a request and render a JSON response for example.
| 59 | // Context is the most important part of gin. It allows us to pass variables between middleware, |
| 60 | // manage the flow, validate the JSON of a request and render a JSON response for example. |
| 61 | type Context struct { |
| 62 | writermem responseWriter |
| 63 | Request *http.Request |
| 64 | Writer ResponseWriter |
| 65 | |
| 66 | Params Params |
| 67 | handlers HandlersChain |
| 68 | index int8 |
| 69 | fullPath string |
| 70 | |
| 71 | engine *Engine |
| 72 | params *Params |
| 73 | skippedNodes *[]skippedNode |
| 74 | |
| 75 | // This mutex protects Keys map. |
| 76 | mu sync.RWMutex |
| 77 | |
| 78 | // Keys is a key/value pair exclusively for the context of each request. |
| 79 | Keys map[any]any |
| 80 | |
| 81 | // Errors is a list of errors attached to all the handlers/middlewares who used this context. |
| 82 | Errors errorMsgs |
| 83 | |
| 84 | // Accepted defines a list of manually accepted formats for content negotiation. |
| 85 | Accepted []string |
| 86 | |
| 87 | // queryCache caches the query result from c.Request.URL.Query(). |
| 88 | queryCache url.Values |
| 89 | |
| 90 | // formCache caches c.Request.PostForm, which contains the parsed form data from POST, PATCH, |
| 91 | // or PUT body parameters. |
| 92 | formCache url.Values |
| 93 | |
| 94 | // SameSite allows a server to define a cookie attribute making it impossible for |
| 95 | // the browser to send this cookie along with cross-site requests. |
| 96 | sameSite http.SameSite |
| 97 | } |
| 98 | |
| 99 | /************************************/ |
| 100 | /********** CONTEXT CREATION ********/ |
nothing calls this directly
no outgoing calls
no test coverage detected