forked from tobischo/gokeepasslib
/
root_data.go
44 lines (36 loc) · 1.18 KB
/
root_data.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
package gokeepasslib
type RootDataOption func(*RootData)
func WithRootDataFormattedTime(formatted bool) RootDataOption {
return func(rd *RootData) {
for _, group := range rd.Groups {
WithGroupFormattedTime(formatted)(&group)
}
}
}
// RootData stores the actual content of a database (all enteries sorted into groups and the recycle bin)
type RootData struct {
Groups []Group `xml:"Group"`
DeletedObjects []DeletedObjectData `xml:"DeletedObjects>DeletedObject"`
}
// NewRootData returns a RootData struct with good defaults
func NewRootData(options ...RootDataOption) *RootData {
root := new(RootData)
group := NewGroup()
group.Name = "NewDatabase"
entry := NewEntry()
entry.Values = append(entry.Values, ValueData{Key: "Title", Value: V{Content: "Sample Entry"}})
group.Entries = append(group.Entries, entry)
root.Groups = append(root.Groups, group)
for _, option := range options {
option(root)
}
return root
}
func (rd *RootData) setKdbxFormatVersion(version formatVersion) {
for i := range rd.Groups {
(&rd.Groups[i]).setKdbxFormatVersion(version)
}
for i := range rd.DeletedObjects {
(&rd.DeletedObjects[i]).setKdbxFormatVersion(version)
}
}