-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.go
50 lines (38 loc) · 950 Bytes
/
profile.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
package main
import (
"fmt"
"regexp"
)
type profile struct {
PathFormat *regexp.Regexp `yaml:"path-format"`
Rules rules `yaml:"rules"`
}
func (p *profile) UnmarshalYAML(unmarshal func(interface{}) error) error {
type uProfile struct {
PathFormat string `yaml:"path-format"`
Rules rules `yaml:"rules"`
}
u := uProfile{}
err := unmarshal(&u)
if err != nil {
return err
}
p.Rules = u.Rules
p.PathFormat, err = regexp.Compile(u.PathFormat)
return err
}
func (p *profile) checkPath(filename string) bool {
return p.PathFormat.MatchString(filename)
}
type profiles map[string]profile
func filterProfiles(p profiles, profileNames []string) (profiles, error) {
filtered := make(profiles, len(profileNames))
for _, profName := range profileNames {
prof, ok := p[profName]
if !ok {
return nil, fmt.Errorf("profile not found: %q", profName)
}
filtered[profName] = prof
}
return filtered, nil
}