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

diff

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package diff provides line-by-line text comparison functionality.

This package compares two text strings and produces a structured diff showing which lines were added, removed, or unchanged.

Example:

result := diff.Compare(oldText, newText)
for _, line := range result.Lines {
    fmt.Printf("%s: %s\n", line.Type, line.Content)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Line

type Line struct {
	Type    LineType
	OldLine *int
	NewLine *int
	Content string
}

Line represents a single line in a diff

type LineType

type LineType string

LineType represents the type of change in a diff line

const (
	LineTypeUnchanged LineType = "unchanged"
	LineTypeAdded     LineType = "added"
	LineTypeRemoved   LineType = "removed"
)

type Result

type Result struct {
	Lines []Line
}

Result represents the result of comparing two texts

func Compare

func Compare(oldText, newText string) Result

Compare generates a line-by-line diff between two text strings

Jump to

Keyboard shortcuts

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