-
Notifications
You must be signed in to change notification settings - Fork 1
/
rules.go
36 lines (30 loc) · 791 Bytes
/
rules.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
package conval
import (
"embed"
"fmt"
"path"
"strings"
)
// use the cabrillo name as filename and identifier, see https://www.contestcalendar.com/cabnames.php
//go:embed rules/*.yaml
var definitions embed.FS
func IncludedDefinition(name string) (*Definition, error) {
filename := fmt.Sprintf("rules/%s.yaml", strings.ToLower(strings.TrimSpace(name)))
f, err := definitions.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
return LoadDefinitionYAML(f)
}
func IncludedDefinitionNames() ([]string, error) {
entries, err := definitions.ReadDir("rules")
if err != nil {
return nil, err
}
result := make([]string, len(entries))
for i, entry := range entries {
result[i] = strings.TrimSuffix(entry.Name(), path.Ext(entry.Name()))
}
return result, nil
}