2022-10-24 15:06:49 +00:00
|
|
|
package components
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
*Block
|
|
|
|
FilePath string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) FindDirectives(directiveName string) []IDirective {
|
|
|
|
return c.Block.FindDirectives(directiveName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) FindUpstreams() []*Upstream {
|
|
|
|
var upstreams []*Upstream
|
|
|
|
directives := c.Block.FindDirectives("upstream")
|
|
|
|
for _, directive := range directives {
|
|
|
|
upstreams = append(upstreams, directive.(*Upstream))
|
|
|
|
}
|
|
|
|
return upstreams
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) FindServers() []*Server {
|
|
|
|
var servers []*Server
|
|
|
|
directives := c.Block.FindDirectives("server")
|
|
|
|
for _, directive := range directives {
|
|
|
|
servers = append(servers, directive.(*Server))
|
|
|
|
}
|
|
|
|
return servers
|
|
|
|
}
|
2022-11-24 02:28:39 +00:00
|
|
|
|
|
|
|
func (c *Config) FindHttp() *Http {
|
|
|
|
var http *Http
|
|
|
|
directives := c.Block.FindDirectives("http")
|
|
|
|
if len(directives) > 0 {
|
|
|
|
http = directives[0].(*Http)
|
|
|
|
}
|
|
|
|
|
|
|
|
return http
|
|
|
|
}
|
2022-11-30 09:33:30 +00:00
|
|
|
|
|
|
|
var repeatKeys = map[string]struct {
|
|
|
|
}{
|
2023-01-11 07:15:48 +00:00
|
|
|
"limit_conn": {},
|
|
|
|
"limit_conn_zone": {},
|
|
|
|
"set": {},
|
|
|
|
"if": {},
|
|
|
|
"proxy_set_header": {},
|
2023-04-12 13:52:30 +00:00
|
|
|
"location": {},
|
2023-04-14 08:01:06 +00:00
|
|
|
"include": {},
|
2023-04-24 09:48:22 +00:00
|
|
|
"sub_filter": {},
|
2022-11-30 09:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func IsRepeatKey(key string) bool {
|
|
|
|
if _, ok := repeatKeys[key]; ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|