comparison pkg/middleware/notfound.go @ 1127:71ba4a66ec95

Return 404 if a proxied service is not found.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 07 Nov 2018 16:08:25 +0100
parents
children 04967d6565fa
comparison
equal deleted inserted replaced
1125:dbc663b74724 1127:71ba4a66ec95
1 // This is Free Software under GNU Affero General Public License v >= 3.0
2 // without warranty, see README.md and license for details.
3 //
4 // SPDX-License-Identifier: AGPL-3.0-or-later
5 // License-Filename: LICENSES/AGPL-3.0.txt
6 //
7 // Copyright (C) 2018 by via donau
8 // – Österreichische Wasserstraßen-Gesellschaft mbH
9 // Software engineering by Intevation GmbH
10 //
11 // Author(s):
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
13
14 package middleware
15
16 import (
17 "errors"
18 "net/http"
19 )
20
21 var ErrNotFound = errors.New("Not found")
22
23 func NotFound(next http.Handler) http.Handler {
24 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
25 defer func() {
26 if p := recover(); p != nil {
27 if p == ErrNotFound {
28 http.NotFound(rw, req)
29 } else {
30 panic(p)
31 }
32 }
33 }()
34 next.ServeHTTP(rw, req)
35 })
36 }