Mercurial > gemma
annotate pkg/middleware/notfound.go @ 5520:05db984d3db1
Improve performance of bottleneck area calculation
Avoid buffer calculations by replacing them with simple distance comparisons
and calculate the boundary of the result geometry only once per iteration.
In some edge cases with very large numbers of iterations, this reduced
the runtime of a bottleneck import by a factor of more than twenty.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 21 Oct 2021 19:50:39 +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 } |