output

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package output renders reports as table / JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(w io.Writer, r Report, format string) error

func RenderDiff

func RenderDiff(w io.Writer, d DiffReport, format string) error

RenderDiff writes the diff report as table / json / markdown (PR-comment friendly).

func ResourceCostTotal

func ResourceCostTotal(rc ResourceCost) float64

ResourceCostTotal sums the MonthlyCost of all components in a single resource.

func ValidateFiniteReport added in v0.4.0

func ValidateFiniteReport(r Report) error

ValidateFiniteReport rejects any component or aggregate that cannot be safely represented as finite JSON/table output.

Types

type CostComponent

type CostComponent struct {
	Name        string              `json:"name"`
	Unit        string              `json:"unit"`
	HourlyCost  float64             `json:"hourly_cost"`
	MonthlyCost float64             `json:"monthly_cost"`
	Currency    string              `json:"currency"`
	Usage       *UsageEvidence      `json:"usage,omitempty"`
	Rate        *RateEvidence       `json:"rate,omitempty"`
	Provenance  *ProvenanceEvidence `json:"provenance,omitempty"`
}

type CurrencyDiffTotal added in v0.4.0

type CurrencyDiffTotal struct {
	Currency string  `json:"currency"`
	Before   float64 `json:"before"`
	After    float64 `json:"after"`
	Delta    float64 `json:"delta"`
}

type DiffKind

type DiffKind string

DiffKind is + (added), - (removed), ~ (changed), = (unchanged).

const (
	DiffAdd    DiffKind = "+"
	DiffRemove DiffKind = "-"
	DiffChange DiffKind = "~"
	DiffSame   DiffKind = "="
)

type DiffReport

type DiffReport struct {
	Resources        []ResourceDiff      `json:"resources"`
	Skipped          []SkippedResource   `json:"skipped"`
	BeforeTotal      float64             `json:"before_total"`
	AfterTotal       float64             `json:"after_total"`
	DeltaTotal       float64             `json:"delta_total"`
	Currency         string              `json:"currency"`
	TotalsByCurrency []CurrencyDiffTotal `json:"totals_by_currency,omitempty"`
	TotalsComplete   bool                `json:"totals_complete"`
	AggregationError string              `json:"aggregation_error,omitempty"`
	Policy           any                 `json:"policy,omitempty"`
}

func ComputeDiff

func ComputeDiff(before, after Report) DiffReport

ComputeDiff preserves the original convenience API. Invalid externally-built reports produce an explicit aggregation error rather than non-finite numbers.

func ComputeDiffChecked added in v0.4.0

func ComputeDiffChecked(before, after Report) (DiffReport, error)

ComputeDiffChecked pairs resources by address and computes monthly deltas, rejecting any non-finite component or aggregate before it can reach JSON.

type ProvenanceEvidence added in v0.4.0

type ProvenanceEvidence struct {
	Kind   string         `json:"kind"`
	Source SourceEvidence `json:"source"`
}

type RateEvidence added in v0.4.0

type RateEvidence struct {
	Amount   float64 `json:"amount"`
	Per      float64 `json:"per"`
	Currency string  `json:"currency"`
}

type Report

type Report struct {
	Resources []ResourceCost    `json:"resources"`
	Skipped   []SkippedResource `json:"skipped"`
	Policy    any               `json:"policy,omitempty"`
}

func (Report) Total

func (r Report) Total() float64

Total returns the sum of MonthlyCost over all cost components. Callers that accept external reports should call ValidateFiniteReport first.

type ResourceCost

type ResourceCost struct {
	Address    string          `json:"address"`
	Type       string          `json:"type"`
	Components []CostComponent `json:"components"`
}

type ResourceDiff

type ResourceDiff struct {
	Address       string   `json:"address"`
	Type          string   `json:"type"`
	Kind          DiffKind `json:"kind"`
	BeforeMonthly float64  `json:"before_monthly"`
	AfterMonthly  float64  `json:"after_monthly"`
	DeltaMonthly  float64  `json:"delta_monthly"`
	Uncertain     bool     `json:"uncertain,omitempty"`
}

type SkippedResource

type SkippedResource struct {
	Address  string `json:"address"`
	Type     string `json:"type"`
	Reason   string `json:"reason"`
	Category string `json:"category,omitempty"`
}

type SourceEvidence added in v0.4.0

type SourceEvidence struct {
	Kind       string `json:"kind"`
	Reference  string `json:"reference"`
	AsOf       string `json:"as_of"`
	Confidence string `json:"confidence"`
}

type UsageEvidence added in v0.4.0

type UsageEvidence struct {
	Quantity float64 `json:"quantity"`
	Unit     string  `json:"unit"`
}

Jump to

Keyboard shortcuts

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