summaryrefslogtreecommitdiff
path: root/router_test.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-02-15 16:44:29 -0700
committertjpcc <tjp@ctrl-c.club>2023-02-15 16:44:29 -0700
commit46ad450327111b9d28b592658d75ef57da498298 (patch)
tree2b837bac9ae36d5a34dda06ba745850da216257d /router_test.go
parentbc96af40db6104580c22086c8db7c8119a404257 (diff)
Switch Handler to an interface.
HandlerFunc is much better as a function returning a Handler, rather than a newtype for the function type itself. This way there is no confusion creating a type-inferenced variable with HandlerFunc(func(... and then using a HandlerFunc where a Handler is expected. Much better to only have one public type.
Diffstat (limited to 'router_test.go')
-rw-r--r--router_test.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/router_test.go b/router_test.go
index 6f9c915..bfc48bd 100644
--- a/router_test.go
+++ b/router_test.go
@@ -13,24 +13,24 @@ import (
"tildegit.org/tjp/gus/gemini"
)
-func h1(_ context.Context, _ *gus.Request) *gus.Response {
+var h1 = gus.HandlerFunc(func(_ context.Context, _ *gus.Request) *gus.Response {
return gemini.Success("", &bytes.Buffer{})
-}
+})
func mw1(h gus.Handler) gus.Handler {
- return func(ctx context.Context, req *gus.Request) *gus.Response {
- resp := h(ctx, req)
+ return gus.HandlerFunc(func(ctx context.Context, req *gus.Request) *gus.Response {
+ resp := h.Handle(ctx, req)
resp.Body = io.MultiReader(resp.Body, bytes.NewBufferString("\nmiddleware 1"))
return resp
- }
+ })
}
func mw2(h gus.Handler) gus.Handler {
- return func(ctx context.Context, req *gus.Request) *gus.Response {
- resp := h(ctx, req)
+ return gus.HandlerFunc(func(ctx context.Context, req *gus.Request) *gus.Response {
+ resp := h.Handle(ctx, req)
resp.Body = io.MultiReader(resp.Body, bytes.NewBufferString("\nmiddleware 2"))
return resp
- }
+ })
}
func TestRouterUse(t *testing.T) {