/
cfg.go
80 lines (69 loc) · 1.78 KB
/
cfg.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package proxy
import (
"fmt"
"strings"
"time"
"github.com/fagongzi/gateway/pkg/util"
)
// Option proxy option
type Option struct {
LimitCountDispatchWorker uint64
LimitCountCopyWorker uint64
LimitCountHeathCheckWorker int
LimitCountConn int
LimitIntervalHeathCheck time.Duration
LimitDurationConnKeepalive time.Duration
LimitDurationConnIdle time.Duration
LimitTimeoutWrite time.Duration
LimitTimeoutRead time.Duration
LimitBufferRead int
LimitBufferWrite int
LimitBytesBody int
LimitBytesCaching uint64
JWTCfgFile string
EnableWebSocket bool
}
// Cfg proxy config
type Cfg struct {
Addr string
AddrRPC string
AddrStore string
AddrPPROF string
Namespace string
TTLProxy int64
Filers []*FilterSpec
Option *Option
Metric *util.MetricCfg
}
// AddFilter add a filter
func (c *Cfg) AddFilter(filter *FilterSpec) {
c.Filers = append(c.Filers, filter)
}
// FilterSpec filter spec
type FilterSpec struct {
Name string `json:"name"`
External bool `json:"external,omitempty"`
ExternalPluginFile string `json:"externalPluginFile,omitempty"`
ExternalCfg string `json:"externalCfg,omitempty"`
}
// ParseFilter returns a filter
func ParseFilter(filter string) (*FilterSpec, error) {
specs := strings.Split(filter, ":")
switch len(specs) {
case 1:
return &FilterSpec{Name: specs[0]}, nil
case 2:
return &FilterSpec{
Name: specs[0],
External: true,
ExternalPluginFile: specs[1]}, nil
case 3:
return &FilterSpec{
Name: specs[0],
External: true,
ExternalPluginFile: specs[1],
ExternalCfg: specs[2]}, nil
default:
return nil, fmt.Errorf("error format: %s", filter)
}
}