forked from tobischo/gokeepasslib
/
group.go
66 lines (54 loc) · 1.98 KB
/
group.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
package gokeepasslib
import (
w "github.com/footmau/gokeepasslib/wrappers"
)
type GroupOption func(*Group)
func WithGroupFormattedTime(formatted bool) GroupOption {
return func(g *Group) {
WithTimeDataFormattedTime(formatted)(&g.Times)
for _, group := range g.Groups {
WithGroupFormattedTime(formatted)(&group)
}
for _, entry := range g.Entries {
WithEntryFormattedTime(formatted)(&entry)
}
}
}
// Group is a structure to store entries in their named groups for organization
type Group struct {
UUID UUID `xml:"UUID"`
Name string `xml:"Name"`
Notes string `xml:"Notes"`
IconID int64 `xml:"IconID"`
CustomIconUUID UUID `xml:"CustomIconUUID"`
Times TimeData `xml:"Times"`
IsExpanded w.BoolWrapper `xml:"IsExpanded"`
DefaultAutoTypeSequence string `xml:"DefaultAutoTypeSequence"`
EnableAutoType w.NullableBoolWrapper `xml:"EnableAutoType"`
EnableSearching w.NullableBoolWrapper `xml:"EnableSearching"`
LastTopVisibleEntry string `xml:"LastTopVisibleEntry"`
Entries []Entry `xml:"Entry,omitempty"`
Groups []Group `xml:"Group,omitempty"`
}
// NewGroup returns a new group with time data and uuid set
func NewGroup(options ...GroupOption) Group {
group := Group{
EnableAutoType: w.NewNullableBoolWrapper(true),
EnableSearching: w.NewNullableBoolWrapper(true),
Times: NewTimeData(),
UUID: NewUUID(),
}
for _, option := range options {
option(&group)
}
return group
}
func (g *Group) setKdbxFormatVersion(version formatVersion) {
(&g.Times).setKdbxFormatVersion(version)
for i := range g.Groups {
(&g.Groups[i]).setKdbxFormatVersion(version)
}
for i := range g.Entries {
(&g.Entries[i]).setKdbxFormatVersion(version)
}
}