From b8c55a3c5cb48c5dfac5de4fccceb4d97df12a12 Mon Sep 17 00:00:00 2001 From: Kenta Iwasaki Date: Mon, 11 May 2020 23:33:08 +0900 Subject: [PATCH] handler, readme: allow ContextHandler to load from another context as well, and add request lifecycle to readme --- README.md | 46 +++++++++++++++++++++++++++++++++++++++++++++- handler.go | 8 ++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ae848c2..556342a 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,48 @@ [![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](LICENSE) [![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/lithdew/flatend) -[![Discord Chat](https://img.shields.io/discord/697002823123992617)](https://discord.gg/HZEbkeQ) \ No newline at end of file +[![Discord Chat](https://img.shields.io/discord/697002823123992617)](https://discord.gg/HZEbkeQ) + +## Request Lifecycle + +```asciidoc ++-------+ +|Request| ++-------+ - +| +v ++------------------------------+ +|Negotiate codec for | +|decoding input/encoding output| ++------------------------------+ +| +v ++--------------------+ +|Grab | +|1) route parameters | +|2) query parameters | +|3) header parameters| ++--------------------+ +| +v ++----------------------+ +|Decode body parameters| +|using codec | ++----------------------+ +| +v ++-----------------------------+ +|Execute handler w/ parameters| ++-----------------------------+ +| +v ++---------------------+ +|Encode handler output| +|using codec | ++---------------------+ +| +v ++--------+ +|Response| ++--------+ +``` \ No newline at end of file diff --git a/handler.go b/handler.go index 2f3825e..bc267be 100644 --- a/handler.go +++ b/handler.go @@ -20,6 +20,7 @@ var ( _ http.Handler = (*ContentLengthHandler)(nil) _ http.Handler = (*ContentDecodeHandler)(nil) + _ ContextLoader = (*ContextHandler)(nil) _ ContextLoader = (*ContentTypeHandler)(nil) _ ContextLoader = (*ContentLengthHandler)(nil) _ ContextLoader = (*ContentDecodeHandler)(nil) @@ -51,6 +52,13 @@ type ContextHandler struct { } } +func (h *ContextHandler) LoadContext(other *Context) { + h.Codecs = other.Codecs + h.DefaultCodec = other.DefaultCodec + h.MinContentLength = other.MinContentLength + h.MaxContentLength = other.MaxContentLength +} + func (h *ContextHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { in := acquireValues() out := acquireValues()