exprfuncs

package
v3.9.0 Latest Latest
Warning

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

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

Documentation

Overview

Package exprfuncs contains functions injected into the expr-lang environment for use in spec expressions (e.g. table columns, body params).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Coalesce

func Coalesce(vals ...any) any

Coalesce returns the first argument that is non-zero. Zero values are: nil, empty string, integer/float 0, and boolean false.

func Duration

func Duration(startMs, endMs any) string

Duration formats the elapsed time between two epoch-millisecond timestamps as a human-readable string ("5m20s" or "42s"). Returns "" when either value is zero. Accepts any numeric type since JSON numbers arrive as float64 in untyped maps.

func Env added in v3.8.0

func Env(name string, def ...string) string

Env returns the value of the named environment variable, or def (default "") when it is unset or empty.

func EpochMs

func EpochMs(v any) string

EpochMs formats an epoch-millisecond timestamp as "2006-01-02 15:04:05" UTC. Accepts any numeric type. Returns "" for zero or unrecognized input.

func FormatMetadata

func FormatMetadata(m map[string]string) []map[string]string

FormatMetadata converts a map[string]string (from --set flags) into the []map[string]string shape the Harness metadata API expects: [{key, value}, ...].

func FormatOrder

func FormatOrder(order, subOrder any) string

FormatOrder formats an activity order/sub_order pair as "N" or "N.M". sub_order of 0 is omitted. Accepts any numeric type (JSON numbers arrive as float64).

func FormatRoleAssignments

func FormatRoleAssignments(assignments []any) string

FormatRoleAssignments converts a roleAssignmentMetadata slice to a JSON array of "roleName (roleScopeLevel)" strings.

func FormatRoleIds

func FormatRoleIds(assignments []any) string

FormatRoleIds converts a roleAssignmentMetadata slice to a JSON array of "roleIdentifier:roleScopeLevel" strings.

func FormatTagDisplay

func FormatTagDisplay(tags map[string]any) string

FormatTagDisplay converts a map[string]string tags value (from the Harness API) into a comma-separated display string. Keys with non-empty values render as "key:value"; keys with empty values render as just "key".

func FormatTags

func FormatTags(s string) map[string]string

FormatTags converts a comma-separated list of tag names into the map[string]string shape the Harness API expects: {"tagname": ""}.

func HarScopeUrl

func HarScopeUrl(auth map[string]any) string

HarScopeUrl returns the HAR UI URL path segment for the given auth map. account-only → "" org-only → "/orgs/{org}" project → "/orgs/{org}/projects/{project}"

func IsBlank

func IsBlank(v any) bool

IsBlank reports whether v is nil or an empty string.

func JsonArray

func JsonArray(v []any) string

JsonArray marshals a slice to a compact JSON array string. Returns "[]" for nil.

func JsonArrayPretty added in v3.7.1

func JsonArrayPretty(v []any) string

JsonArrayPretty marshals a slice to an indented (2-space) JSON array string. Returns "[]" for nil.

func LastPart

func LastPart(s string) string

LastPart returns the last "/"-delimited segment of s. If s contains no "/", the whole string is returned. Useful when an ID may be prefixed with an optional parent scope (e.g. "pipeline/executionId" or just "executionId").

func NewPipelineSparkline

func NewPipelineSparkline(isPty bool) func(any) string

NewPipelineSparkline returns a sparkline closure using ANSI escapes (pty) or plain ASCII.

func NewPrLabelColor

func NewPrLabelColor(enabled bool) func(color, text string) string

NewLabelColor returns a function that colorizes text using the nearest basic ANSI color for a Harness Code label color. When enabled is false (non-PTY or machine format), the returned function always returns text unchanged.

func NewStatusIcon

func NewStatusIcon(enabled bool) func(string) string

NewStatusIcon returns a function that maps a Harness execution status string to a colored icon string. When enabled is false (non-PTY or machine format), the returned function always returns "".

func ParseDateMs

func ParseDateMs(v any) string

ParseDateMs converts a date string to epoch milliseconds (as a string). Accepts: YYYY-MM-DD, YYYY-MM-DDTHH:MM:SS, epoch ms (passthrough), or relative durations like "30d" (30 days ago), "2w" (2 weeks ago), "1m" (1 month ago). Returns "" for empty or unrecognized input.

Zoneless dates and times are read in the local zone, so "2026-06-01" means midnight where the user is. Epoch millis and relative spans are absolute.

func SpaceAfter

func SpaceAfter(s string) string

SpaceAfter returns s + " " if s is non-empty, otherwise "". Useful for conditionally padding an icon before adjacent text.

func Substr

func Substr(s string, start, n int) string

Substr returns a substring of s starting at rune index start, up to length n runes. Negative start counts from the end. If start or end is out of bounds it is clamped.

func Truncate

func Truncate(s string, n int) string

Truncate collapses all whitespace (newlines, tabs, runs of spaces) in s to single spaces, trims leading/trailing space, then truncates to n runes, appending "…" if the string was shortened.

Types

This section is empty.

Jump to

Keyboard shortcuts

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