diff options
| author | Adnan Maolood <[email protected]> | 2021-02-23 20:40:22 -0500 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2021-02-23 20:41:16 -0500 |
| commit | a65c3c3d4f88c088eda47802bd5a1db9c4b39190 (patch) | |
| tree | 92ef503ec279443b316e9b3096a7f77ef5340c78 /handler.go | |
| parent | handler: Mention when the context is canceled (diff) | |
| download | go-gemini-a65c3c3d4f88c088eda47802bd5a1db9c4b39190.tar.xz go-gemini-a65c3c3d4f88c088eda47802bd5a1db9c4b39190.zip | |
Make ResponseWriter a struct
Make ResponseWriter a struct again so that it can be extended in a
backwards-compatible way.
Diffstat (limited to 'handler.go')
| -rw-r--r-- | handler.go | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -19,23 +19,23 @@ import ( // // Handlers should not modify the provided Request. type Handler interface { - ServeGemini(context.Context, ResponseWriter, *Request) + ServeGemini(context.Context, *ResponseWriter, *Request) } // The HandlerFunc type is an adapter to allow the use of ordinary functions // as Gemini handlers. If f is a function with the appropriate signature, // HandlerFunc(f) is a Handler that calls f. -type HandlerFunc func(context.Context, ResponseWriter, *Request) +type HandlerFunc func(context.Context, *ResponseWriter, *Request) // ServeGemini calls f(ctx, w, r). -func (f HandlerFunc) ServeGemini(ctx context.Context, w ResponseWriter, r *Request) { +func (f HandlerFunc) ServeGemini(ctx context.Context, w *ResponseWriter, r *Request) { f(ctx, w, r) } // StatusHandler returns a request handler that responds to each request // with the provided status code and meta. func StatusHandler(status Status, meta string) Handler { - return HandlerFunc(func(ctx context.Context, w ResponseWriter, r *Request) { + return HandlerFunc(func(ctx context.Context, w *ResponseWriter, r *Request) { w.WriteHeader(status, meta) }) } @@ -56,7 +56,7 @@ func StripPrefix(prefix string, h Handler) Handler { if prefix == "" { return h } - return HandlerFunc(func(ctx context.Context, w ResponseWriter, r *Request) { + return HandlerFunc(func(ctx context.Context, w *ResponseWriter, r *Request) { p := strings.TrimPrefix(r.URL.Path, prefix) rp := strings.TrimPrefix(r.URL.RawPath, prefix) if len(p) < len(r.URL.Path) && (r.URL.RawPath == "" || len(rp) < len(r.URL.RawPath)) { |