-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinternal.go
45 lines (40 loc) · 1.08 KB
/
internal.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
package plugin_cond_redirect
import (
"fmt"
"github.com/mitchellh/mapstructure"
"net/http"
"regexp"
)
type redirectRule struct {
withHost bool
source *regexp.Regexp
destination string
condition redirectCondition
}
type redirectCondition interface {
check(request *http.Request) bool
}
func (raw *RawRedirectCondition) refine() (RedirectCondition, error) {
if raw.T == "header" {
var result HeaderRedirectCondition
err := mapstructure.Decode(raw.Data, &result)
return result, err
} else if raw.T == "cookie" {
var result CookieRedirectCondition
err := mapstructure.Decode(raw.Data, &result)
return result, err
} else if raw.T == "and" {
var result AndRedirectCondition
err := mapstructure.Decode(raw.Data, &result)
return result, err
} else if raw.T == "or" {
var result OrRedirectCondition
err := mapstructure.Decode(raw.Data, &result)
return result, err
} else if raw.T == "not" {
var result NotRedirectCondition
err := mapstructure.Decode(raw.Data, &result)
return result, err
}
return nil, fmt.Errorf("unknown condition type: %s", raw.T)
}