forked from tufanbarisyildirim/gonginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.go
31 lines (27 loc) · 832 Bytes
/
block.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
package gonginx
//Block a block statement
type Block struct {
Directives []IDirective
}
//GetDirectives get all directives in this block
func (b *Block) GetDirectives() []IDirective {
return b.Directives
}
//FindDirectives find directives in block recursively
func (b *Block) FindDirectives(directiveName string) []IDirective {
directives := make([]IDirective, 0)
for _, directive := range b.GetDirectives() {
if directive.GetName() == directiveName {
directives = append(directives, directive)
}
if include, ok := directive.(*Include); ok {
for _, c := range include.Configs {
directives = append(directives, c.FindDirectives(directiveName)...)
}
}
if directive.GetBlock() != nil {
directives = append(directives, directive.GetBlock().FindDirectives(directiveName)...)
}
}
return directives
}