Mercurial > gemma
annotate pkg/middleware/notfound.go @ 5591:0011f50cf216 surveysperbottleneckid
Removed no longer used alternative api for surveys/ endpoint.
As bottlenecks in the summary for SR imports are now identified by
their id and no longer by the (not guarantied to be unique!) name,
there is no longer the need to request survey data by the name+date
tuple (which isn't reliable anyway). So the workaround was now
reversed.
author | Sascha Wilde <wilde@sha-bang.de> |
---|---|
date | Wed, 06 Apr 2022 13:30:29 +0200 |
parents | 6f9d00c8cc38 |
children |
rev | line source |
---|---|
1127
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package middleware |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "errors" |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "net/http" |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 ) |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
1494
04967d6565fa
Added api doc strings for the middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1127
diff
changeset
|
21 // ErrNotFound should be as the argument to panic if the NotFound should |
04967d6565fa
Added api doc strings for the middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1127
diff
changeset
|
22 // report back a http.StatusNotFound. |
4164
6f9d00c8cc38
Made 'golint' and 'staticcheck' happy with middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1494
diff
changeset
|
23 var ErrNotFound = errors.New("not found") |
1127
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 |
1494
04967d6565fa
Added api doc strings for the middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1127
diff
changeset
|
25 // NotFound creates an http.Handler which survives panic(ErrNotFound) and |
04967d6565fa
Added api doc strings for the middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1127
diff
changeset
|
26 // reports http.StatusNotFound in these cases back to the calling handler. |
1127
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 func NotFound(next http.Handler) http.Handler { |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 defer func() { |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 if p := recover(); p != nil { |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 if p == ErrNotFound { |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 http.NotFound(rw, req) |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 } else { |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 panic(p) |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 } |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 } |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 }() |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 next.ServeHTTP(rw, req) |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 }) |
71ba4a66ec95
Return 404 if a proxied service is not found.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |