-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
teler.go
46 lines (37 loc) · 917 Bytes
/
teler.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
package teler
import (
"fmt"
"github.com/teler-sh/teler-waf"
"github.com/teler-sh/teler-waf/option"
)
// Loader is a function type that loads teler WAF options from a file path or
// string.
type Loader func(string) (teler.Options, error)
// getTelerOptions based on the Caddyfile definition.
func getTelerOptions(m *Middleware) (teler.Options, error) {
var loader Loader
var opt teler.Options
if m.LoadFrom != "" {
switch m.Format {
case json:
loader = option.LoadFromJSONFile
case yaml:
loader = option.LoadFromYAMLFile
default:
return opt, fmt.Errorf(errUnsupportedFormat, m.Format)
}
return loader(m.LoadFrom)
}
if m.Inline != "" {
switch m.Format {
case json:
loader = option.LoadFromJSONString
case yaml:
loader = option.LoadFromYAMLString
default:
return opt, fmt.Errorf(errUnsupportedFormat, m.Format)
}
return loader(m.Inline)
}
return opt, nil
}