-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathproblem.go
More file actions
85 lines (72 loc) · 2.14 KB
/
problem.go
File metadata and controls
85 lines (72 loc) · 2.14 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package letsdebug
import (
"fmt"
"strings"
)
// SeverityLevel represents the priority of a reported problem
type SeverityLevel string
// Problem represents an issue found by one of the checkers in this package.
// Explanation is a human-readable explanation of the issue.
// Detail is usually the underlying machine error.
type Problem struct {
Name string `json:"name"`
Explanation string `json:"explanation"`
Detail string `json:"detail"`
Severity SeverityLevel `json:"severity"`
}
const (
SeverityInfo SeverityLevel = "Info" // Represents informational messages which are not necessarily a problem.
SeverityFatal SeverityLevel = "Fatal" // Represents a fatal error which will stop any further checks
SeverityError SeverityLevel = "Error"
SeverityWarning SeverityLevel = "Warning"
SeverityDebug SeverityLevel = "Debug" // Not to be shown by default
)
func (p Problem) String() string {
return fmt.Sprintf("[%s] %s: %s", p.Name, p.Explanation, p.Detail)
}
func (p Problem) IsZero() bool {
return p.Name == ""
}
func (p Problem) DetailLines() []string {
return strings.Split(p.Detail, "\n")
}
func hasFatalProblem(probs []Problem) bool {
for _, p := range probs {
if p.Severity == SeverityFatal {
return true
}
}
return false
}
func internalProblem(message string, level SeverityLevel) Problem {
return Problem{
Name: "InternalProblem",
Explanation: "An internal error occurred while checking the domain",
Detail: message,
Severity: level,
}
}
func dnsLookupFailed(name, rrType string, err error) Problem {
return Problem{
Name: "DNSLookupFailed",
Explanation: fmt.Sprintf(`A fatal issue occurred during the DNS lookup process for %s/%s.`, name, rrType),
Detail: err.Error(),
Severity: SeverityFatal,
}
}
func debugProblem(name, message, detail string) Problem {
return Problem{
Name: name,
Explanation: message,
Detail: detail,
Severity: SeverityDebug,
}
}
func infoProblem(name, message, detail string) Problem {
return Problem{
Name: name,
Explanation: message,
Detail: detail,
Severity: SeverityInfo,
}
}