Skip to content

Commit

Permalink
Added helpers for some predicates and filters
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Klijn <[email protected]>
  • Loading branch information
peterklijn committed Oct 3, 2020
1 parent 3507fc9 commit 61d97d8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
50 changes: 50 additions & 0 deletions filters/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package filters

import (
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/filters/cookie"
"strconv"
)

func Status(statusCode int) *eskip.Filter {
return &eskip.Filter{
Name: builtin.StatusName,
Args: []interface{}{statusCode},
}
}

func InlineContent(text string) *eskip.Filter {
return &eskip.Filter{
Name: builtin.InlineContentName,
Args: []interface{}{text},
}
}

func InlineContentWithMime(text, mime string) *eskip.Filter {
return &eskip.Filter{
Name: builtin.InlineContentName,
Args: []interface{}{text, mime},
}
}

func PreserveHost(preserve bool) *eskip.Filter {
return &eskip.Filter{
Name: builtin.PreserveHostName,
Args: []interface{}{strconv.FormatBool(preserve)},
}
}

func ResponseCookie(name, value string) *eskip.Filter {
return &eskip.Filter{
Name: cookie.ResponseCookieFilterName,
Args: []interface{}{name, value},
}
}

func ResponseCookieWithSettings(name, value string, ttl float64, changeOnly bool) *eskip.Filter {
return &eskip.Filter{
Name: cookie.ResponseCookieFilterName,
Args: []interface{}{name, value, ttl, changeOnly},
}
}
28 changes: 28 additions & 0 deletions predicates/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package predicates

import (
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/predicates/traffic"
"github.com/zalando/skipper/routing"
)

func Path(path string) *eskip.Predicate {
return &eskip.Predicate{
Name: routing.PathName,
Args: []interface{}{path},
}
}

func Traffic(chance float64) *eskip.Predicate {
return &eskip.Predicate{
Name: traffic.PredicateName,
Args: []interface{}{chance},
}
}

func TrafficSticky(chance float64, trafficGroupCookie, trafficGroup string) *eskip.Predicate {
return &eskip.Predicate{
Name: traffic.PredicateName,
Args: []interface{}{chance, trafficGroupCookie, trafficGroup},
}
}

0 comments on commit 61d97d8

Please sign in to comment.