-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
51 lines (42 loc) · 1.29 KB
/
option.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
package derp
// Option defines a function that modifies a derp.Error
type Option func(*Error)
func WithCode(code int) Option {
return func(e *Error) {
e.Code = code
}
}
// WithBadRequest returns an option that sets the derp.Error code to 400 (Bad Request)
func WithBadRequest() Option {
return WithCode(CodeBadRequestError)
}
// WithForbidden returns an option that sets the derp.Error code to 403 (Forbidden)
func WithForbidden() Option {
return WithCode(CodeForbiddenError)
}
// WithNotFound returns an option that sets the derp.Error code to 404 (Not Found)
func WithNotFound() Option {
return WithCode(CodeNotFoundError)
}
// WithInternalError returns an option that sets the derp.Error code to 500 (Internal Server Error)
func WithInternalError() Option {
return WithCode(CodeInternalError)
}
// WithWrappedValue returns an option that sets the derp.Error wrapped value
func WithWrappedValue(inner error) Option {
return func(e *Error) {
e.WrappedValue = inner
}
}
// WithMessage returns an option that sets the derp.Error message
func WithMessage(message string) Option {
return func(e *Error) {
e.Message = message
}
}
// WithLocation returns an option that sets the derp.Error location
func WithLocation(location string) Option {
return func(e *Error) {
e.Location = location
}
}