patch

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package patch provides merge-patch utilities for TOML and JSON documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalJSON

func MarshalJSON(doc any) ([]byte, error)

MarshalJSON encodes a map as indented JSON bytes.

func MarshalTOML

func MarshalTOML(doc any) ([]byte, error)

MarshalTOML encodes a map as TOML bytes.

func Merge

func Merge(original, patch any) any

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

func ReadJSON(path string) (map[string]any, error)

ReadJSON reads and parses a JSON file into a map. Returns an empty map if the file does not exist.

func ReadTOML

func ReadTOML(path string) (map[string]any, error)

ReadTOML reads and parses a TOML file into a map. Returns an empty map if the file does not exist.

func SetNestedValue

func SetNestedValue(doc map[string]any, section, key string, value any)

SetNestedValue sets doc[section][key] = value, creating the section map if needed.

func UnmarshalJSON

func UnmarshalJSON(data []byte) (map[string]any, error)

UnmarshalJSON parses raw JSON bytes into a map.

func UnmarshalTOML

func UnmarshalTOML(data []byte) (map[string]any, error)

UnmarshalTOML parses raw TOML bytes into a map.

func WriteFileAtomic

func WriteFileAtomic(path string, content []byte, perm os.FileMode) error

WriteFileAtomic writes content to path atomically by writing to a temp file first, then renaming.

func WriteJSON

func WriteJSON(path string, doc any) error

WriteJSON atomically encodes doc as indented JSON and writes it to path.

func WriteTOML

func WriteTOML(path string, doc map[string]any) error

WriteTOML atomically encodes doc as TOML and writes it to path via temp-file + rename.

Types

This section is empty.

Jump to

Keyboard shortcuts

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