summaryrefslogtreecommitdiff
path: root/handler.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-08-12 09:40:39 -0600
committertjpcc <tjp@ctrl-c.club>2023-08-12 09:40:39 -0600
commit23bc5f4fb7542e64c94eaa7fe2c7a6aa55010898 (patch)
treeec8113d3aa2379e3ca9cb3c6e13a5531895ea8c0 /handler.go
parent57a31a9b2cd549174d839b9b91b47db337f174cc (diff)
move common types to an internal package
This helps avoid import cycles.
Diffstat (limited to 'handler.go')
-rw-r--r--handler.go28
1 files changed, 7 insertions, 21 deletions
diff --git a/handler.go b/handler.go
index 1c2d6dc..f3c9edd 100644
--- a/handler.go
+++ b/handler.go
@@ -1,33 +1,19 @@
package sliderule
-import "context"
+import (
+ "context"
-// Handler is a type which can turn a request into a response.
-//
-// Handle may return a nil response, in which case the Server is expected
-// to build the protocol-appropriate "Not Found" response.
-type Handler interface {
- Handle(context.Context, *Request) *Response
-}
+ "tildegit.org/tjp/sliderule/internal/types"
+)
-type handlerFunc func(context.Context, *Request) *Response
+type Handler = types.Handler
+type Middleware = types.Middleware
// HandlerFunc is a wrapper to allow using a function as a Handler.
func HandlerFunc(f func(context.Context, *Request) *Response) Handler {
- return handlerFunc(f)
-}
-
-// Handle implements Handler.
-func (f handlerFunc) Handle(ctx context.Context, request *Request) *Response {
- return f(ctx, request)
+ return types.HandlerFunc(f)
}
-// Middleware is a handler decorator.
-//
-// It returns a handler which may call the passed-in handler or not, or may
-// transform the request or response in some way.
-type Middleware func(Handler) Handler
-
// FallthroughHandler builds a handler which tries multiple child handlers.
//
// The returned handler will invoke each of the passed-in handlers in order,