forked from zalando/skipper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
35 lines (26 loc) · 853 Bytes
/
status.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
package builtin
import "github.com/zalando/skipper/filters"
type statusSpec struct{}
type statusFilter int
// Creates a filter specification whose instances set the
// status of the response to a fixed value regardless of
// backend response.
func NewStatus() filters.Spec { return new(statusSpec) }
func (s *statusSpec) Name() string { return StatusName }
func (s *statusSpec) CreateFilter(args []interface{}) (filters.Filter, error) {
if len(args) != 1 {
return nil, filters.ErrInvalidFilterParameters
}
switch c := args[0].(type) {
case int:
return statusFilter(c), nil
case float64:
return statusFilter(c), nil
default:
return nil, filters.ErrInvalidFilterParameters
}
}
func (f statusFilter) Request(filters.FilterContext) {}
func (f statusFilter) Response(ctx filters.FilterContext) {
ctx.Response().StatusCode = int(f)
}