...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package errors
16
17 import (
18 "bytes"
19 "fmt"
20 "strings"
21 )
22
23
24
25 type APIVerificationFailed struct {
26 Section string `json:"section,omitempty"`
27 MissingSpecification []string `json:"missingSpecification,omitempty"`
28 MissingRegistration []string `json:"missingRegistration,omitempty"`
29 }
30
31 func (v *APIVerificationFailed) Error() string {
32 buf := bytes.NewBuffer(nil)
33
34 hasRegMissing := len(v.MissingRegistration) > 0
35 hasSpecMissing := len(v.MissingSpecification) > 0
36
37 if hasRegMissing {
38 buf.WriteString(fmt.Sprintf("missing [%s] %s registrations", strings.Join(v.MissingRegistration, ", "), v.Section))
39 }
40
41 if hasRegMissing && hasSpecMissing {
42 buf.WriteString("\n")
43 }
44
45 if hasSpecMissing {
46 buf.WriteString(fmt.Sprintf("missing from spec file [%s] %s", strings.Join(v.MissingSpecification, ", "), v.Section))
47 }
48
49 return buf.String()
50 }
51
View as plain text