-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresponse_types.go
161 lines (128 loc) · 2.92 KB
/
response_types.go
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package vitali
//204
type noContent struct {
}
func (c *Ctx) NoContent() noContent {
return noContent{}
}
//301
type movedPermanently struct {
uri string
}
func (c *Ctx) MovedPermanently(uri string) movedPermanently {
return movedPermanently{uri}
}
// 302
type found struct {
uri string
}
func (c *Ctx) Found(uri string) found {
return found{uri}
}
// 303
type seeOther struct {
uri string
}
func (c *Ctx) SeeOther(uri string) seeOther {
return seeOther{uri}
}
// 307
type tempRedirect struct {
uri string
}
func (c *Ctx) TempRedirect(uri string) tempRedirect {
return tempRedirect{uri}
}
// 400
type badRequest struct {
body interface{}
reason string
}
func (c *Ctx) BadRequest(reason string, bodies ...interface{}) badRequest {
return badRequest{extractBody(bodies), reason}
}
// 401
type unauthorized struct {
body interface{}
wwwAuthHeader string
}
func (c *Ctx) Unauthorized(wwwAuthHeader string, bodies ...interface{}) unauthorized {
return unauthorized{extractBody(bodies), wwwAuthHeader}
}
// 403
type forbidden struct {
body interface{}
}
func (c *Ctx) Forbidden(bodies ...interface{}) forbidden {
return forbidden{extractBody(bodies)}
}
// 404
type notFound struct {
body interface{}
}
func (c *Ctx) NotFound(bodies ...interface{}) notFound {
return notFound{extractBody(bodies)}
}
// 405
type methodNotAllowed struct {
allowed []string
}
func (c *Ctx) MethodNotAllowed(allowed []string) methodNotAllowed {
return methodNotAllowed{allowed}
}
//406
type notAcceptable struct {
provided MediaTypes
}
func (c *Ctx) NotAcceptable(provided MediaTypes) notAcceptable {
return notAcceptable{provided}
}
// 415
type unsupportedMediaType struct {
body interface{}
}
func (c *Ctx) UnsupportedMediaType(bodies ...interface{}) unsupportedMediaType {
return unsupportedMediaType{extractBody(bodies)}
}
// 501
type notImplemented struct {
body interface{}
}
func (c *Ctx) NotImplemented(bodies ...interface{}) notImplemented {
return notImplemented{extractBody(bodies)}
}
// 503
type serviceUnavailable struct {
body interface{}
seconds int
}
func (c *Ctx) ServiceUnavailable(seconds int, bodies ...interface{}) serviceUnavailable {
return serviceUnavailable{extractBody(bodies), seconds}
}
// return this if client is disconnected
type clientGone struct {
}
func (c *Ctx) ClientGone() clientGone {
return clientGone{}
}
// return this if something bad leads to internal server error
type internalError struct {
where string
why string
code uint32
}
func (c *Ctx) InternalError(e error) internalError {
return internalError {
where: lineInfo(1),
why: e.Error(),
code: errorCode(e.Error()),
}
}
func extractBody(bodies []interface{}) interface{}{
var body interface{}
if len(bodies) > 0 {
// Only uses first element as body
body = bodies[0]
}
return body
}