/
teeloopback.go
51 lines (41 loc) · 1.13 KB
/
teeloopback.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 tee
import (
log "github.com/sirupsen/logrus"
"github.com/zalando/skipper/filters"
teepredicate "github.com/zalando/skipper/predicates/tee"
)
// FilterName is the filter name
// Deprecated, use filters.TeeLoopbackName instead
const FilterName = filters.TeeLoopbackName
type teeLoopbackSpec struct{}
type teeLoopbackFilter struct {
teeKey string
}
func (t *teeLoopbackSpec) Name() string {
return filters.TeeLoopbackName
}
func (t *teeLoopbackSpec) CreateFilter(args []interface{}) (filters.Filter, error) {
if len(args) != 1 {
return nil, filters.ErrInvalidFilterParameters
}
teeKey, _ := args[0].(string)
if teeKey == "" {
return nil, filters.ErrInvalidFilterParameters
}
return &teeLoopbackFilter{
teeKey,
}, nil
}
func NewTeeLoopback() filters.Spec {
return &teeLoopbackSpec{}
}
func (f *teeLoopbackFilter) Request(ctx filters.FilterContext) {
cc, err := ctx.Split()
if err != nil {
log.Errorf("teeloopback: failed to split the context request: %v", err)
return
}
cc.Request().Header.Set(teepredicate.HeaderKey, f.teeKey)
go cc.Loopback()
}
func (f *teeLoopbackFilter) Response(_ filters.FilterContext) {}