Documentation
¶
Overview ¶
Package plist provides plist parsing and writing for Apple configuration files. Supports XML, binary, and JSON plist formats.
Parsing ¶
Parse plist data from any format with auto-detection:
data, _ := os.ReadFile("Info.plist")
v, err := plist.ParseBytes(data)
// Or parse directly from a file
v, err := plist.ParseFile("Info.plist")
Accessing Values ¶
Use typed accessor functions with key paths:
bundleID := plist.String(v, "CFBundleIdentifier") version := plist.Int(v, "CFBundleVersion")
Struct Marshal/Unmarshal ¶
Encode and decode Go structs using the "plist" struct tag:
type Info struct {
BundleID string `plist:"CFBundleIdentifier"`
Version int `plist:"CFBundleVersion"`
}
data, err := plist.Marshal(info, plist.FormatXML)
var info Info
_, err := plist.Unmarshal(data, &info)
Writing ¶
Write plist data in any supported format:
plist.WriteXML(os.Stdout, v)
plist.WriteJSON(os.Stdout, v)
plist.WriteBinary(os.Stdout, v)
plist.WriteToFile("output.plist", v, plist.FormatXML)
NSKeyedArchiver and UID ¶
Binary plists produced by NSKeyedArchiver use UID values to reference objects in the $objects array. The UID type preserves these references when parsing and writing binary plists:
v, _ := plist.ParseBytes(data) m := v.(map[string]any) top := m["$top"].(map[string]any) ref := top["root"].(plist.UID) // UID referencing an entry in $objects
Index ¶
- func Array(v any, keys ...string) []any
- func Bool(v any, keys ...string) bool
- func Bytes(v any, keys ...string) []byte
- func CreateEmpty() map[string]any
- func Dict(v any, keys ...string) map[string]any
- func Float(v any, keys ...string) float64
- func Get(v any, keys ...string) any
- func Int(v any, keys ...string) int
- func Int64(v any, keys ...string) int64
- func Lint(data []byte) error
- func LintFile(path string) error
- func Marshal(v any, format Format) ([]byte, error)
- func Parse(r io.Reader) (any, error)
- func ParseBytes(data []byte) (any, error)
- func ParseFile(path string) (any, error)
- func Remove(v any, keypath string) (any, error)
- func Set(v any, keypath string, value any) (any, error)
- func String(v any, keys ...string) string
- func TypeOf(v any) string
- func WriteBinary(w io.Writer, v any) error
- func WriteJSON(w io.Writer, v any) error
- func WriteToFile(path string, v any, format Format) error
- func WriteXML(w io.Writer, v any) error
- type Format
- type UID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateEmpty ¶
CreateEmpty creates an empty plist (empty dictionary).
func Marshal ¶
Marshal encodes a Go value into plist data in the specified format. Struct fields are encoded using the "plist" struct tag. If no tag is present, the field name is used. The "omitempty" option causes the field to be omitted when it has a zero value.
func ParseBytes ¶
ParseBytes parses plist data (auto-detects format).
func WriteBinary ¶
WriteBinary writes plist data as binary to a writer.
func WriteToFile ¶
WriteToFile writes plist data to a file in the specified format.
Types ¶
type Format ¶
type Format int
Format represents a plist format.
func DetectFormat ¶
DetectFormat detects the plist format from data.
type UID ¶ added in v0.2.2
type UID uint64
UID represents a unique identifier used in NSKeyedArchiver binary plists. In keyed archives, UID values reference objects in the $objects array. UID implements fmt.Stringer, encoding.TextMarshaler, encoding.TextUnmarshaler, and the json marshal/unmarshal interfaces.
func (UID) MarshalJSON ¶ added in v0.2.2
MarshalJSON encodes the UID as a JSON number.
func (UID) MarshalText ¶ added in v0.2.2
MarshalText encodes the UID as a decimal string.
func (*UID) UnmarshalJSON ¶ added in v0.2.2
UnmarshalJSON decodes a JSON number into a UID.
func (*UID) UnmarshalText ¶ added in v0.2.2
UnmarshalText decodes a decimal string into a UID.