/
validate.go
58 lines (41 loc) · 935 Bytes
/
validate.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
51
52
53
54
55
56
57
58
package validate
import (
"fmt"
)
type Options struct {
ValidatePlacetype bool
ValidateRepo bool
ValidateSFOLevel bool
}
func DefaultValidateOptions() *Options {
return &Options{
ValidatePlacetype: true,
ValidateRepo: true,
ValidateSFOLevel: true,
}
}
func Validate(body []byte) error {
opts := DefaultValidateOptions()
return ValidateWithOptions(body, opts)
}
func ValidateWithOptions(body []byte, options *Options) error {
if options.ValidatePlacetype {
err := ValidatePlacetype(body)
if err != nil {
return fmt.Errorf("Failed to validate sfomuseum:placetype, %w", err)
}
}
if options.ValidateRepo {
err := ValidateRepo(body)
if err != nil {
return fmt.Errorf("Failed to validate wof:repo, %w", err)
}
}
if options.ValidateSFOLevel {
err := ValidateSFOLevel(body)
if err != nil {
return fmt.Errorf("Failed to validate sfo:level, %w", err)
}
}
return nil
}