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

output

package
v1.233.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package output provides functionality to format and export component outputs (e.g. Terraform outputs, CloudFormation stack Outputs) in various formats suitable for CI/CD workflows, scripts, and configuration files.

Index

Constants

View Source
const DefaultFileMode = 0o644

DefaultFileMode is the file mode for output files.

View Source
const DefaultFlattenSeparator = "_"

DefaultFlattenSeparator is the default separator for flattening nested keys.

Variables

ScalarOnlyFormats are formats that only support scalar values (not maps/lists).

View Source
var SupportedFormats = []string{"json", "yaml", "hcl", "env", "dotenv", "bash", "csv", "tsv", "table", "github"}

SupportedFormats lists all supported output formats.

Functions

func FlattenMap

func FlattenMap(m map[string]any, prefix, separator string) map[string]any

FlattenMap recursively flattens nested maps and arrays into a single-level map with compound keys. For example: {"config": {"host": "localhost", "port": 3000}} becomes {"config_host": "localhost", "config_port": 3000} with separator "_". Arrays are flattened with numeric indices: {"hosts": ["a", "b"]} becomes {"hosts_0": "a", "hosts_1": "b"}.

func FormatOutputs

func FormatOutputs(outputs map[string]any, format Format) (string, error)

FormatOutputs converts an outputs map to the specified format.

func FormatOutputsWithOptions

func FormatOutputsWithOptions(outputs map[string]any, format Format, opts FormatOptions) (string, error)

FormatOutputsWithOptions converts terraform outputs map to the specified format with options.

func FormatSingleValue

func FormatSingleValue(key string, value any, format Format) (string, error)

FormatSingleValue formats a single terraform output value. For scalar formats (env, dotenv, bash, csv, tsv), complex values (maps/lists) are not supported. For structured formats (json, yaml, hcl), any value type is supported.

func FormatSingleValueWithOptions

func FormatSingleValueWithOptions(key string, value any, format Format, opts FormatOptions) (string, error)

FormatSingleValueWithOptions formats a single terraform output value with options.

func IsComplexValue

func IsComplexValue(value any) bool

IsComplexValue returns true if the value is a map or slice (not a scalar).

func ValidateSingleValueFormat

func ValidateSingleValueFormat(value any, format Format) error

ValidateSingleValueFormat checks if a format supports a single complex value. CSV/TSV formats do not support single complex values (maps/lists).

func WriteToFile

func WriteToFile(filePath string, content string) error

WriteToFile writes content to a file, creating it if it doesn't exist or appending to it if it does.

Types

type Format

type Format string

Format represents output format types.

const (
	// FormatJSON outputs as JSON object: {"key": "value"}.
	FormatJSON Format = "json"
	// FormatYAML outputs as YAML: key: value.
	FormatYAML Format = "yaml"
	// FormatHCL outputs as HCL: key = "value".
	FormatHCL Format = "hcl"
	// FormatEnv outputs as env vars: key=value (GitHub Actions style).
	FormatEnv Format = "env"
	// FormatDotenv outputs as dotenv: key='value'.
	FormatDotenv Format = "dotenv"
	// FormatBash outputs as bash exports: export key='value'.
	FormatBash Format = "bash"
	// FormatCSV outputs as CSV: key,value.
	FormatCSV Format = "csv"
	// FormatTSV outputs as TSV: key<tab>value.
	FormatTSV Format = "tsv"
	// FormatTable outputs as a styled table with Key/Value columns.
	FormatTable Format = "table"
	// FormatGitHub outputs for GitHub Actions $GITHUB_OUTPUT file.
	// Uses KEY=value for simple values, heredoc syntax for multiline values.
	FormatGitHub Format = "github"
)

type FormatOptions

type FormatOptions struct {
	// Uppercase converts keys to uppercase (useful for environment variables).
	Uppercase bool
	// Flatten recursively expands nested maps and arrays into flat key/value pairs.
	// For example, {"config": {"host": "localhost"}} becomes {"config_host": "localhost"}.
	// Arrays are flattened with numeric indices: {"hosts": ["a", "b"]} becomes {"hosts_0": "a", "hosts_1": "b"}.
	Flatten bool
	// FlattenSeparator is the separator used when flattening nested keys (default: "_").
	FlattenSeparator string
	// AtmosConfig provides configuration for syntax highlighting and color preferences.
	AtmosConfig *schema.AtmosConfiguration
}

FormatOptions provides options for output formatting.

func (FormatOptions) GetFlattenSeparator

func (o FormatOptions) GetFlattenSeparator() string

GetFlattenSeparator returns the flatten separator, using the default if not set.

Jump to

Keyboard shortcuts

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