output

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package output provides structured output formatting for gpd.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

type Format string

Format represents the output format type.

const (
	FormatJSON     Format = "json"
	FormatTable    Format = "table"
	FormatMarkdown Format = "markdown"
	FormatCSV      Format = "csv"   // Only for analytics/vitals
	FormatExcel    Format = "excel" // Excel (.xlsx) format
)

func ParseFormat

func ParseFormat(s string) Format

ParseFormat parses a format string into a Format type.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles output formatting and writing.

func NewManager

func NewManager(w io.Writer) *Manager

NewManager creates a new output manager.

func (*Manager) SetFields

func (m *Manager) SetFields(fields []string) *Manager

SetFields sets field projection paths.

func (*Manager) SetFormat

func (m *Manager) SetFormat(f Format) *Manager

SetFormat sets the output format.

func (*Manager) SetPretty

func (m *Manager) SetPretty(pretty bool) *Manager

SetPretty enables pretty printing for JSON.

func (*Manager) Write

func (m *Manager) Write(r *Result) error

Write formats and writes the result.

type Metadata

type Metadata struct {
	// Core fields (always present)
	NoOp       bool     `json:"noop"`
	DurationMs int64    `json:"durationMs"`
	Services   []string `json:"services"`

	// Optional pagination fields
	RequestID     string `json:"requestId,omitempty"`
	PageToken     string `json:"pageToken,omitempty"`
	NextPageToken string `json:"nextPageToken,omitempty"`
	HasMorePages  *bool  `json:"hasMorePages,omitempty"`

	// Optional warning/info fields
	Warnings []string `json:"warnings,omitempty"`

	// Extended fields for specific operations
	Partial          bool       `json:"partial,omitempty"`
	ScannedCount     int        `json:"scannedCount,omitempty"`
	FilteredCount    int        `json:"filteredCount,omitempty"`
	TotalAvailable   int        `json:"totalAvailable,omitempty"`
	Retries          int        `json:"retries,omitempty"`
	DataFreshnessUTC *time.Time `json:"dataFreshnessUtc,omitempty"`
	NoOpReason       string     `json:"noopReason,omitempty"`
}

Metadata contains response metadata.

type Result

type Result struct {
	Data     interface{}      `json:"data"`
	Error    *errors.APIError `json:"error"`
	Meta     *Metadata        `json:"meta"`
	ExitCode int              `json:"-"` // Process state only, not in JSON
}

Result represents the standard JSON envelope structure.

func NewEmptyResult

func NewEmptyResult() *Result

NewEmptyResult creates a result with no data (for operations that don't return data).

func NewErrorResult

func NewErrorResult(err *errors.APIError) *Result

NewErrorResult creates an error result.

func NewResult

func NewResult(data interface{}) *Result

NewResult creates a successful result with data.

func (*Result) WithDuration

func (r *Result) WithDuration(d time.Duration) *Result

WithDuration sets the duration metadata.

func (*Result) WithNoOp

func (r *Result) WithNoOp(reason string) *Result

WithNoOp marks the result as a no-op with a reason.

func (*Result) WithPagination

func (r *Result) WithPagination(pageToken, nextPageToken string) *Result

WithPagination sets pagination metadata.

func (*Result) WithPartial

func (r *Result) WithPartial(scanned, filtered, total int) *Result

WithPartial marks the result as partial with scan metadata.

func (*Result) WithRequestID

func (r *Result) WithRequestID(id string) *Result

WithRequestID sets the request ID metadata.

func (*Result) WithRetries

func (r *Result) WithRetries(count int) *Result

WithRetries sets the retry count metadata.

func (*Result) WithServices

func (r *Result) WithServices(services ...string) *Result

WithServices sets the services metadata.

func (*Result) WithWarnings

func (r *Result) WithWarnings(warnings ...string) *Result

WithWarnings adds warnings to the result.

Jump to

Keyboard shortcuts

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