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

truncate

package
v0.19.12 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxLines   = 2000
	DefaultMaxBytes   = 50 * 1024
	GrepMaxLineLength = 500
	// MaxSafeInteger is JavaScript's Number.MAX_SAFE_INTEGER, clamped to int on 32-bit targets.
	MaxSafeInteger = min(1<<53-1, math.MaxInt)
)

Variables

This section is empty.

Functions

func FormatSize

func FormatSize(bytes int) string

func Int

func Int(value int) *int

Types

type LineResult

type LineResult struct {
	Text         string `json:"text"`
	WasTruncated bool   `json:"wasTruncated"`
}

func TruncateLine

func TruncateLine(line string, maxChars ...int) LineResult

type Options

type Options struct {
	MaxLines *int `json:"maxLines,omitempty"`
	MaxBytes *int `json:"maxBytes,omitempty"`
}

Options uses pointers because zero is an upstream-visible limit, while nil means the option was omitted and selects the default.

type Reason

type Reason string
const (
	ReasonLines Reason = "lines"
	ReasonBytes Reason = "bytes"
)

type Result

type Result struct {
	Content               string  `json:"content"`
	Truncated             bool    `json:"truncated"`
	TruncatedBy           *Reason `json:"truncatedBy"`
	TotalLines            int     `json:"totalLines"`
	TotalBytes            int     `json:"totalBytes"`
	OutputLines           int     `json:"outputLines"`
	OutputBytes           int     `json:"outputBytes"`
	LastLinePartial       bool    `json:"lastLinePartial"`
	FirstLineExceedsLimit bool    `json:"firstLineExceedsLimit"`
	MaxLines              int     `json:"maxLines"`
	MaxBytes              int     `json:"maxBytes"`
}

func TruncateHead

func TruncateHead(content string, options ...Options) Result

func TruncateTail

func TruncateTail(content string, options ...Options) Result

Jump to

Keyboard shortcuts

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