Skip to content

Commit

Permalink
handler, readme: allow ContextHandler to load from another context as…
Browse files Browse the repository at this point in the history
… well, and add request lifecycle to readme
  • Loading branch information
lithdew committed May 11, 2020
1 parent a5d210a commit b8c55a3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
[![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|
+--------+
```
8 changes: 8 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b8c55a3

Please sign in to comment.