Help us shape the future of Go! Take the 2026 Go Developer Survey

diff

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: GPL-3.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Delete = gotextdiff.Delete
	Insert = gotextdiff.Insert
	Equal  = gotextdiff.Equal
)

Variables

This section is empty.

Functions

func Format

func Format(w io.Writer, u Unified)

Format writes a unified diff to w.

func FormatString

func FormatString(u Unified) string

FormatString renders a unified diff as a string.

func FormatSummary

func FormatSummary(w io.Writer, result *DiffResult)

FormatSummary writes a compact list of changed resources.

func FormatUnifiedDiff

func FormatUnifiedDiff(w io.Writer, result *DiffResult)

FormatUnifiedDiff writes a plain-text summary of the diff.

func ReorderFilter

func ReorderFilter() func([]*yaml.RNode) ([]*yaml.RNode, error)

ReorderFilter returns a kio.Filter that reorders fields in each manifest to follow Kubernetes conventions: apiVersion, kind, metadata, spec, status, ... Unknown fields are preserved at the end in their original order.

Types

type DiffChangeJSON

type DiffChangeJSON struct {
	ObjectRef   ObjectRef      `json:"objectRef"`
	Old         map[string]any `json:"old"`
	New         map[string]any `json:"new"`
	UnifiedDiff string         `json:"unifiedDiff"`
}

DiffChangeJSON represents a modified resource with before/after snapshots.

type DiffResult

type DiffResult struct {
	Added    []ObjectRef
	Removed  []ObjectRef
	Modified []ResourceChange
}

DiffResult holds the structured result of a diff between two manifest sets.

func DiffNodes

func DiffNodes(before, after []*yaml.RNode) (*DiffResult, error)

DiffNodes computes a semantic diff between two sets of Kubernetes manifests. Resources are matched by identity (apiVersion + kind + namespace + name).

func (*DiffResult) HasChanges

func (r *DiffResult) HasChanges() bool

HasChanges reports whether any resources were added, removed, or modified.

type DiffResultJSON

type DiffResultJSON struct {
	Added    []map[string]any `json:"added"`
	Deleted  []ObjectRef      `json:"deleted"`
	Modified []DiffChangeJSON `json:"modified"`
}

DiffResultJSON is the JSON representation of a manifest diff.

func DiffNodesJSON

func DiffNodesJSON(before, after []*yaml.RNode) (*DiffResultJSON, error)

DiffNodesJSON computes a diff and returns a JSON-serializable result.

type Hunk

type Hunk = gotextdiff.Hunk

Re-export gotextdiff types so consumers don't need to import it directly.

type Line

type Line = gotextdiff.Line

Re-export gotextdiff types so consumers don't need to import it directly.

type ObjectRef

type ObjectRef struct {
	APIVersion string `json:"apiVersion"`
	Kind       string `json:"kind"`
	Name       string `json:"name"`
	Namespace  string `json:"namespace,omitempty"`
}

ObjectRef mirrors the Kubernetes ObjectReference shape used in Events, OwnerReferences, and other cross-resource references.

func ObjectRefFromMeta

func ObjectRefFromMeta(meta yaml.ResourceMeta) ObjectRef

ObjectRefFromMeta builds an ObjectRef from kyaml ResourceMeta.

func (ObjectRef) String

func (o ObjectRef) String() string

String returns a human-readable identifier for the resource.

type OpKind

type OpKind = gotextdiff.OpKind

Re-export gotextdiff types so consumers don't need to import it directly.

type ResourceChange

type ResourceChange struct {
	Key    ObjectRef
	Before string
	After  string
	Diff   Unified
}

ResourceChange describes a single modified resource.

type Unified

type Unified = gotextdiff.Unified

Re-export gotextdiff types so consumers don't need to import it directly.

func ComputeDiff

func ComputeDiff(name, before, after string) Unified

ComputeDiff computes a Myers diff between two multi-line strings and returns a Unified diff structure.

Jump to

Keyboard shortcuts

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