-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathplist.go
39 lines (31 loc) · 799 Bytes
/
plist.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
package alfred
import (
"fmt"
"os"
"howett.net/plist"
)
// Plist is a plist data structure
type Plist map[string]interface{}
// LoadPlist loads a plist from an XML file
func LoadPlist(filename string) (p Plist) {
var err error
var xmlData []byte
if xmlData, err = os.ReadFile(filename); err != nil {
panic(fmt.Errorf("error reading plist file: %s", err))
}
if _, err = plist.Unmarshal(xmlData, &p); err != nil {
panic(err)
}
return
}
// SavePlist saves a plist to an XML file
func SavePlist(filename string, p Plist) {
var err error
var xmlData []byte
if xmlData, err = plist.MarshalIndent(p, plist.XMLFormat, "\t"); err != nil {
panic(fmt.Errorf("error serializing plist data: %s", err))
}
if err = os.WriteFile(filename, xmlData, 0644); err != nil {
panic(err)
}
}