Documentation
¶
Overview ¶
Package reportutil provides type-safe accessors for map[string]any fields.
Index ¶
- Constants
- Variables
- func DecodeBinaryEnvelope(reader io.Reader) ([]byte, error)
- func DecodeBinaryEnvelopes(data []byte) ([][]byte, error)
- func EncodeBinaryEnvelope(value any, writer io.Writer) error
- func FormatFloat(v float64) string
- func FormatInt(v int) string
- func FormatPercent(v float64) string
- func GetAs[T any](report map[string]any, key string) (T, bool)
- func GetFloat64(report map[string]any, key string) float64
- func GetFunctions(report map[string]any, key string) []map[string]any
- func GetInt(report map[string]any, key string) int
- func GetString(report map[string]any, key string) string
- func GetStringIntMap(report map[string]any, key string) map[string]int
- func GetStringSlice(report map[string]any, key string) []string
- func MapString(m map[string]any, key string) string
- func Pct(count, total int) float64
Constants ¶
const (
// BinaryMagic marks Codefang binary envelopes.
BinaryMagic = "CFB1"
)
const (
PercentMultiplier = 100
)
Formatting constants.
Variables ¶
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 ¶
DecodeBinaryEnvelope extracts the JSON payload from a binary envelope.
func DecodeBinaryEnvelopes ¶
DecodeBinaryEnvelopes decodes all concatenated binary envelopes from bytes.
func EncodeBinaryEnvelope ¶
EncodeBinaryEnvelope serializes any JSON-serializable value into a binary envelope.
func FormatFloat ¶
FormatFloat formats a float64 with 1 decimal place.
func FormatPercent ¶
FormatPercent formats a float64 (0-1) as a percentage string.
func GetAs ¶
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 ¶
GetFloat64 returns a float64 value from the report, handling type conversion. Delegates to safeconv.ToFloat64 for consistent type handling.
func GetFunctions ¶
GetFunctions returns the []map[string]any for the given key. Handles both direct []map[string]any and TypedCollection values.
func GetInt ¶
GetInt returns an int value from the report, handling type conversion. Delegates to safeconv.ToInt for consistent type handling.
func GetStringIntMap ¶
GetStringIntMap returns a map[string]int value from the report.
func GetStringSlice ¶
GetStringSlice returns a []string value from the report.
Types ¶
This section is empty.