reportutil

package
v1.0.0-rc.1 Latest Latest
Warning

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

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

Documentation

Overview

Package reportutil provides type-safe accessors for map[string]any fields.

Index

Constants

View Source
const (
	// BinaryMagic marks Codefang binary envelopes.
	BinaryMagic = "CFB1"
)
View Source
const (
	PercentMultiplier = 100
)

Formatting constants.

Variables

View Source
var (
	// ErrInvalidBinaryEnvelope indicates malformed or truncated binary payload.
	ErrInvalidBinaryEnvelope = errors.New("invalid binary envelope")
	// ErrBinaryPayloadTooLarge indicates payload exceeds binary envelope limit.
	ErrBinaryPayloadTooLarge = errors.New("binary payload too large")
)

Functions

func DecodeBinaryEnvelope

func DecodeBinaryEnvelope(reader io.Reader) ([]byte, error)

DecodeBinaryEnvelope extracts the JSON payload from a binary envelope.

func DecodeBinaryEnvelopes

func DecodeBinaryEnvelopes(data []byte) ([][]byte, error)

DecodeBinaryEnvelopes decodes all concatenated binary envelopes from bytes.

func EncodeBinaryEnvelope

func EncodeBinaryEnvelope(value any, writer io.Writer) error

EncodeBinaryEnvelope serializes any JSON-serializable value into a binary envelope.

func FormatFloat

func FormatFloat(v float64) string

FormatFloat formats a float64 with 1 decimal place.

func FormatInt

func FormatInt(v int) string

FormatInt formats an int as a string.

func FormatPercent

func FormatPercent(v float64) string

FormatPercent formats a float64 (0-1) as a percentage string.

func GetAs

func GetAs[T any](report map[string]any, key string) (T, bool)

GetAs extracts a value of type T from a report map via direct type assertion. Returns (zero, false) if the key is absent or the value is not of type T. For numeric types requiring cross-type coercion use GetFloat64 or GetInt.

func GetFloat64

func GetFloat64(report map[string]any, key string) float64

GetFloat64 returns a float64 value from the report, handling type conversion. Delegates to safeconv.ToFloat64 for consistent type handling.

func GetFunctions

func GetFunctions(report map[string]any, key string) []map[string]any

GetFunctions returns the []map[string]any for the given key. Handles both direct []map[string]any and TypedCollection values.

func GetInt

func GetInt(report map[string]any, key string) int

GetInt returns an int value from the report, handling type conversion. Delegates to safeconv.ToInt for consistent type handling.

func GetString

func GetString(report map[string]any, key string) string

GetString returns a string value from the report.

func GetStringIntMap

func GetStringIntMap(report map[string]any, key string) map[string]int

GetStringIntMap returns a map[string]int value from the report.

func GetStringSlice

func GetStringSlice(report map[string]any, key string) []string

GetStringSlice returns a []string value from the report.

func MapString

func MapString(m map[string]any, key string) string

MapString returns a string from a map[string]any.

func Pct

func Pct(count, total int) float64

Pct calculates percentage as float64 (0-1).

Types

This section is empty.

Jump to

Keyboard shortcuts

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