-
Notifications
You must be signed in to change notification settings - Fork 14
/
diagnostics.go
80 lines (67 loc) · 2.45 KB
/
diagnostics.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Nuts node
* Copyright (C) 2021 Nuts community
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
package core
import "fmt"
// DiagnosticResult are the result of different checks giving information on how well the system is doing
type DiagnosticResult interface {
// Name returns a simple and understandable name of the check
Name() string
// Result returns the outcome of the check in its original format. This may be any type that can be marshalled by the JSON package.
Result() interface{}
// String returns the outcome of the check formatted as string
String() string
}
// DiagnosticResultMap is a DiagnosticResult that presents the given Items as a map, rather than a list.
type DiagnosticResultMap struct {
Title string
Items []DiagnosticResult
}
// Name returns the of the diagnostic, which is used as key.
func (g DiagnosticResultMap) Name() string {
return g.Title
}
// Result returns the result of the diagnostic, which is Items converted to a map.
func (g DiagnosticResultMap) Result() interface{} {
result := make(map[string]interface{}, 0)
for _, item := range g.Items {
result[item.Name()] = item.Result()
}
return result
}
// String returns the string representation of Result()
func (g DiagnosticResultMap) String() string {
return fmt.Sprintf("%v", g.Result())
}
// GenericDiagnosticResult is a simple implementation of the DiagnosticResult interface
type GenericDiagnosticResult struct {
Title string
Outcome interface{}
}
// Result returns the raw outcome of the GenericDiagnosticResult
func (gdr GenericDiagnosticResult) Result() interface{} {
return gdr.Outcome
}
// Name returns the name of the GenericDiagnosticResult
func (gdr GenericDiagnosticResult) Name() string {
return gdr.Title
}
// String returns the outcome of the GenericDiagnosticResult
func (gdr GenericDiagnosticResult) String() string {
return fmt.Sprintf("%v", gdr.Outcome)
}