Mercurial > gemma
comparison pkg/middleware/notfound.go @ 1494:04967d6565fa
Added api doc strings for the middleware package.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 04 Dec 2018 17:56:28 +0100 |
parents | 71ba4a66ec95 |
children | 6f9d00c8cc38 |
comparison
equal
deleted
inserted
replaced
1493:11e5ff79e616 | 1494:04967d6565fa |
---|---|
16 import ( | 16 import ( |
17 "errors" | 17 "errors" |
18 "net/http" | 18 "net/http" |
19 ) | 19 ) |
20 | 20 |
21 // ErrNotFound should be as the argument to panic if the NotFound should | |
22 // report back a http.StatusNotFound. | |
21 var ErrNotFound = errors.New("Not found") | 23 var ErrNotFound = errors.New("Not found") |
22 | 24 |
25 // NotFound creates an http.Handler which survives panic(ErrNotFound) and | |
26 // reports http.StatusNotFound in these cases back to the calling handler. | |
23 func NotFound(next http.Handler) http.Handler { | 27 func NotFound(next http.Handler) http.Handler { |
24 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { | 28 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { |
25 defer func() { | 29 defer func() { |
26 if p := recover(); p != nil { | 30 if p := recover(); p != nil { |
27 if p == ErrNotFound { | 31 if p == ErrNotFound { |