CodeVetter · Repo Unpack · Data flow
gin-gonic/gin
HTTP requests enter through Engine.ServeHTTP and acquire reusable framework state. Route lookup transfers path parameters and handler chains into Context; binders transform request data into application values. Renderers serialize those values through a response wrapper that tracks commitment and byte counts. Uploads and logging cross separate filesystem and writer boundaries.
- ServeHTTP gets a Context from Engine.pool, resets its writer and request state, dispatches the request, and returns the Context to the pool after dispatch completes normally.
- handleHTTPRequest chooses EscapedPath before RawPath, optionally cleans extra slashes, then selects the tree matching Request.Method.
- node.getValue stores named and catch-all parameters, optionally applies url.QueryUnescape, and returns handlers and fullPath that dispatch installs on Context.
- ShouldBind selects binding.Default and delegates to Bind; JSON constructs a codec decoder, applies optional number/unknown-field policies, decodes, and validates the destination.
- Form binding parses request values and maps them reflectively; mapping skips '-' tags and non-anonymous unexported fields, traverses structs, and allocates pointers only when populated.
- ShouldBindBodyWith reads the body into bytes once, stores it under BodyBytesKey in Context.Keys, and passes the cached bytes to subsequent BindBody calls.
- Context.Render stages status and delegates output; JSON marshals through json.API, and responseWriter.Write commits headers before writing and accumulating byte counts.
- Uploads flow from ParseMultipartForm to a FileHeader and io.Copy into os.Create(dst); request logging separately emits final status, size, client IP, private errors, and optionally query strings to its configured writer.