forked from viant/assertly
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirectives.go
More file actions
32 lines (29 loc) · 798 Bytes
/
directives.go
File metadata and controls
32 lines (29 loc) · 798 Bytes
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
package assertly
//Directives represent a directive
type Directives struct {
*Directive
PathDirectives map[string]*Directive
}
func (d *Directives) Match(path DataPath) *Directive {
var result = NewDirective(path)
result.mergeFrom(d.Directive)
if matched, ok := d.PathDirectives[path.MatchingPath()]; ok {
result.mergeFrom(matched)
}
return result
}
//NewDirectives returns new directives
func NewDirectives(directives ...*Directive) *Directives {
var result = &Directives{
Directive: NewDirective(NewDataPath("")),
PathDirectives: make(map[string]*Directive),
}
for i, directive := range directives {
if directive.MatchingPath() == "" {
result.Directive = directive
continue
}
result.PathDirectives[directive.MatchingPath()] = directives[i]
}
return result
}