go-don
go-don copied to clipboard
Create abstraction layer for requests
Create a don.Context
interface with an implementation that calls out to fasthttp
.
don.Context
Methods:
-
context.Context
-
io.Reader
(reads from request body) -
io.Writer
(writes to response body) -
Body() []byte
(request body) -
Method() string
-
URL() don.URL
(request URL) -
RequestHeader() don.Header
-
ResponseHeader() don.Header
-
Query() don.Params
(request URL query) -
Path() don.Params
(request path params) -
Status(int) don.Params
(sets status code) -
Redirect(string, int)
-
Decode(any) error
(decode request body, path, header & query to struct) -
Encode(any) error
(encode and write to response body)
don.Header
Methods:
-
Get(string) string
-
Values(string) []string
-
Add(k,v string)
-
Set(k,v string)
-
Range(f func(k,v string))
don.Params
Methods:
-
Get(string) string
-
Values(string) []string
-
Range(f func(k,v string))
Use this interface in middleware and handlers that don't use don.H
. Old style handlers using the fasthttp request directly should also still be supported via an adapter.
This will allow don
to also run on standard lib net/http
down the line by creating a second implementation of don.Context
that wraps the standard lib request & response writer.