/
conf.go
152 lines (132 loc) · 5.12 KB
/
conf.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package conf
import (
"io/ioutil"
"os"
)
var (
Configure string
)
type GlobalConfig struct {
Host string `json:"host" yaml:"host"`
Port string `json:"port" yaml:"port"`
GatewayConfPath string `json:"gateway_conf_path" yaml:"gateway_conf_path"`
GatewayList []GatewayInfo
}
type GatewayInfo struct {
GatewayName string `json:"gateway_name" yaml:"gateway_name"`
GatewayAlias string `json:"gateway_alias" yaml:"gateway_alias"`
GatewayStatus string `json:"gateway_status" yaml:"gateway_status"`
PluginConfPath string `json:"plugin_conf_path" yaml:"plugin_conf_path"`
ApiConfPath string `json:"api_conf_path" yaml:"api_conf_path"`
ApiGroupConfPath string `json:"api_group_conf_path" yaml:"api_group_conf_path"`
StrategyConfPath string `json:"strategy_conf_path" yaml:"strategy_conf_path"`
BackendConfPath string `json:"backend_conf_path" yaml:"backend_conf_path"`
Timeout int `json:"timeout" yaml:"timeout"`
IPLimitType string `json:"ip_limit_type" yaml:"ip_limit_type"`
IPWhiteList []string `json:"ip_white_list" yaml:"ip_white_list"`
IPBlackList []string `json:"ip_black_list" yaml:"ip_black_list"`
StrategyList Strategy
ApiList Api
BackendList Backend
UpdateTime string `json:"update_time" yaml:"update_time"`
CreateTime string `json:"create_time" yaml:"create_time"`
GroupList ApiGroup
}
type Strategy struct {
Strategy []StrategyInfo `json:"strategy" yaml:"strategy"`
}
type StrategyInfo struct {
StrategyName string `json:"strategy_name" yaml:"strategy_name"`
StrategyID string `json:"strategy_id" yaml:"strategy_id"`
Auth string `json:"auth" yaml:"auth"`
BasicUserName string `json:"basic_user_name" yaml:"basic_user_name"`
BasicUserPassword string `json:"basic_user_password" yaml:"basic_user_password"`
ApiKey string `json:"api_key" yaml:"api_key"`
IPLimitType string `json:"ip_limit_type" yaml:"ip_limit_type"`
IPWhiteList []string `json:"ip_white_list" yaml:"ip_white_list"`
IPBlackList []string `json:"ip_black_list" yaml:"ip_black_list"`
RateLimitList []RateLimitInfo `json:"rate_limit_list" yaml:"rate_limit_list"`
UpdateTime string `json:"update_time" yaml:"update_time"`
CreateTime string `json:"create_time" yaml:"create_time"`
}
type RateLimitInfo struct {
Allow bool `json:"allow" yaml:"allow"`
Period string `json:"period" yaml:"period"`
Limit int `json:"limit" yaml:"limit"`
Priority int `json:"priority" yaml:"priority"`
StartTime int `json:"start_time" yaml:"start_time"`
EndTime int `json:"end_time" yaml:"end_time"`
}
type ApiGroupInfo struct {
GroupID int `json:"group_id" yaml:"group_id"`
GroupName string `json:"group_name" yaml:"group_name"`
}
type ApiGroup struct {
Group []ApiGroupInfo `json:"group" yaml:"group"`
}
type Api struct {
Apis []ApiInfo `json:"apis" yaml:"apis"`
}
type ApiInfo struct {
ApiName string `json:"api_name" yaml:"api_name"`
GroupID int `json:"group_id" yaml:"group_id"`
RequestURL string `json:"request_url" yaml:"request_url"`
RequestMethod []string `json:"request_method" yaml:"request_method"`
BackendID int `json:"backend_id" yaml:"backend_id"`
ProxyURL string `json:"proxy_url" yaml:"proxy_url"`
ProxyMethod string `json:"proxy_method" yaml:"proxy_method"`
IsRaw bool `json:"is_raw" yaml:"is_raw"`
ProxyParams []Param `json:"proxy_params" yaml:"proxy_params"`
ConstantParams []ConstantParam `json:"constant_params" yaml:"constant_params"`
Follow bool `json:"follow" yaml:"follow"`
}
type Backend struct {
Backend []BackendInfo `json:"backend" yaml:"backend"`
}
type BackendInfo struct {
BackendID int `json:"backend_id" yaml:"backend_id"`
BackendName string `json:"backend_name" yaml:"backend_name"`
BackendPath string `json:"backend_path" yaml:"backend_path"`
}
type Param struct {
Key string `json:"key" yaml:"key"`
KeyPosition string `json:"key_position" yaml:"key_position"`
NotEmpty bool `json:"not_empty" yaml:"not_empty"`
ProxyKey string `json:"proxy_key" yaml:"proxy_key"`
ProxyKeyPosition string `json:"proxy_key_position" yaml:"proxy_key_position"`
}
type ConstantParam struct {
Position string `json:"position" yaml:"position"`
Key string `json:"key" yaml:"key"`
Value string `json:"value" yaml:"value"`
}
func init() {
Configure = ""
}
func ReadConfigure(filepath string) (err error) {
file, err := os.Open(filepath)
if err != nil {
return
}
content, err := ioutil.ReadAll(file)
if err != nil {
return
}
Configure = string(content)
return
}
// 获取目录内文件夹
func GetDir(dirPth string) (files []string, err error) {
files = make([]string, 0)
dir, err := ioutil.ReadDir(dirPth)
if err != nil {
return nil, err
}
PthSep := string(os.PathSeparator)
for _, fi := range dir {
if fi.IsDir() { // 忽略目录
files = append(files, dirPth+PthSep+fi.Name())
}
}
return files, nil
}