-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
61 lines (45 loc) · 1.31 KB
/
errors.go
File metadata and controls
61 lines (45 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package httpmux
import (
"fmt"
"net/http"
"strings"
)
const (
HeaderAllow = "Allow"
ErrNotFound = ErrStatusHandler(http.StatusNotFound)
)
type ErrStatusHandler int
func (h ErrStatusHandler) Error() string {
return http.StatusText(int(h))
}
func (h ErrStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
serveErrorStatus(w, int(h))
}
type ErrMethodNotAllowed []string
func (_ ErrMethodNotAllowed) Error() string {
return http.StatusText(http.StatusMethodNotAllowed)
}
func (e ErrMethodNotAllowed) Header() string {
return strings.Join(e, ", ")
}
func serveErrorStatus(w http.ResponseWriter, status int) {
http.Error(w, http.StatusText(status), status)
}
type ErrOverlapStaticVar VarName
func (e ErrOverlapStaticVar) Error() string {
return fmt.Sprintf("httpmux: cannot have static path and variable %q at the same location", string(e))
}
type ErrConsecutiveVars struct {
Variable1 VarName
Variable2 VarName
}
func (e *ErrConsecutiveVars) Error() string {
return fmt.Sprintf("httpmux: cannot have two consecutive variables %q and %q", e.Variable1, e.Variable2)
}
type ErrUnequalVars struct {
Variable1 VarName
Variable2 VarName
}
func (e *ErrUnequalVars) Error() string {
return fmt.Sprintf("httpmux: cannot have two unequal variables at the same location %q and %q", e.Variable1, e.Variable2)
}