plist

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Array

func Array(v any, keys ...string) []any

Array retrieves an array at a key path.

func Bool

func Bool(v any, keys ...string) bool

Bool retrieves a bool at a key path.

func Bytes

func Bytes(v any, keys ...string) []byte

Bytes retrieves base64-decoded data at a key path.

func CreateEmpty

func CreateEmpty() map[string]any

CreateEmpty creates an empty plist (empty dictionary).

func Dict

func Dict(v any, keys ...string) map[string]any

Dict retrieves a dict at a key path.

func Float

func Float(v any, keys ...string) float64

Float retrieves a float64 at a key path.

func Get

func Get(v any, keys ...string) any

Get retrieves a value at a key path (dot-separated or variadic).

func Int

func Int(v any, keys ...string) int

Int retrieves an integer at a key path.

func Int64

func Int64(v any, keys ...string) int64

Int64 retrieves an int64 at a key path.

func Lint

func Lint(data []byte) error

Lint validates plist data and returns any errors.

func LintFile

func LintFile(path string) error

LintFile validates a plist file and returns any errors.

func Marshal

func Marshal(v any, format Format) ([]byte, error)

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 Parse

func Parse(r io.Reader) (any, error)

Parse parses plist data from a reader (auto-detects format).

func ParseBytes

func ParseBytes(data []byte) (any, error)

ParseBytes parses plist data (auto-detects format).

func ParseFile

func ParseFile(path string) (any, error)

ParseFile parses a plist file (auto-detects format).

func Remove

func Remove(v any, keypath string) (any, error)

Remove removes a value at a key path. Returns the modified root value.

func Set

func Set(v any, keypath string, value any) (any, error)

Set sets a value at a key path. Returns the modified root value.

func String

func String(v any, keys ...string) string

String retrieves a string at a key path.

func TypeOf

func TypeOf(v any) string

TypeOf returns the plist type name for a value.

func WriteBinary

func WriteBinary(w io.Writer, v any) error

WriteBinary writes plist data as binary to a writer.

func WriteJSON

func WriteJSON(w io.Writer, v any) error

WriteJSON writes plist data as JSON to a writer.

func WriteToFile

func WriteToFile(path string, v any, format Format) error

WriteToFile writes plist data to a file in the specified format.

func WriteXML

func WriteXML(w io.Writer, v any) error

WriteXML writes plist data as XML to a writer.

Types

type Format

type Format int

Format represents a plist format.

const (
	FormatXML Format = iota
	FormatBinary
	FormatJSON
)

func DetectFormat

func DetectFormat(data []byte) Format

DetectFormat detects the plist format from data.

func Unmarshal

func Unmarshal(data []byte, v any) (Format, error)

Unmarshal decodes plist data into a Go value. The value must be a pointer to a struct, map, slice, or other supported type. Returns the detected format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL