Documentation
¶
Overview ¶
Package patch provides merge-patch utilities for TOML and JSON documents.
Index ¶
- func MarshalJSON(doc any) ([]byte, error)
- func MarshalTOML(doc any) ([]byte, error)
- func Merge(original, patch any) any
- func ReadJSON(path string) (map[string]any, error)
- func ReadTOML(path string) (map[string]any, error)
- func SetNestedValue(doc map[string]any, section, key string, value any)
- func UnmarshalJSON(data []byte) (map[string]any, error)
- func UnmarshalTOML(data []byte) (map[string]any, error)
- func WriteFileAtomic(path string, content []byte, perm os.FileMode) error
- func WriteJSON(path string, doc any) error
- func WriteTOML(path string, doc map[string]any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalJSON ¶
MarshalJSON encodes a map as indented JSON bytes.
func MarshalTOML ¶
MarshalTOML encodes a map as TOML bytes.
func Merge ¶
Merge performs a recursive merge-patch of patch into original. nil values in the patch delete the corresponding key from original. Non-map patches replace the original entirely.
func ReadJSON ¶
ReadJSON reads and parses a JSON file into a map. Returns an empty map if the file does not exist.
func ReadTOML ¶
ReadTOML reads and parses a TOML file into a map. Returns an empty map if the file does not exist.
func SetNestedValue ¶
SetNestedValue sets doc[section][key] = value, creating the section map if needed.
func UnmarshalJSON ¶
UnmarshalJSON parses raw JSON bytes into a map.
func UnmarshalTOML ¶
UnmarshalTOML parses raw TOML bytes into a map.
func WriteFileAtomic ¶
WriteFileAtomic writes content to path atomically by writing to a temp file first, then renaming.
Types ¶
This section is empty.