-
Notifications
You must be signed in to change notification settings - Fork 4
/
status.go
61 lines (52 loc) · 1.34 KB
/
status.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
package diff
import (
"projectforge.dev/projectforge/app/util"
)
type Status struct {
Key string
Title string
}
var (
StatusDifferent = &Status{Key: "different", Title: "The files are different"}
StatusIdentical = &Status{Key: "identical", Title: "The files are identical"}
StatusMissing = &Status{Key: "missing", Title: "File is not present in the source"}
StatusNew = &Status{Key: "new", Title: "File is not present in the target"}
StatusSkipped = &Status{Key: "skipped", Title: "File was ignored"}
)
var AllStatuses = []*Status{StatusDifferent, StatusIdentical, StatusMissing, StatusNew, StatusSkipped}
func StatusFromString(s string) *Status {
for _, t := range AllStatuses {
if t.Key == s {
return t
}
}
return nil
}
func (t *Status) String() string {
return t.Key
}
func (t *Status) StringFor(act string) string {
if act == "audit" {
switch t.Key {
case StatusDifferent.Key:
return "Invalid Header"
case StatusMissing.Key:
return "Empty Folder"
default:
return util.StringToTitle(t.Key)
}
}
return util.StringToTitle(t.Key)
}
func (t *Status) MarshalJSON() ([]byte, error) {
return util.ToJSONBytes(t.Key, false), nil
}
func (t *Status) UnmarshalJSON(data []byte) error {
var s string
if err := util.FromJSON(data, &s); err != nil {
return err
}
x := StatusFromString(s)
*t = *x
return nil
}