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)
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
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.