Documentation
¶
Index ¶
- Constants
- func AddAllowFileReadsFlag(cmd *cobra.Command, allow *bool)
- func AddDestFlag(cmd *cobra.Command, dest *string, def string, usage string, aliases ...string)
- func AddFileCacheFlag(cmd *cobra.Command, cache *bool)
- func AddFileRootFlag(cmd *cobra.Command, root *string)
- func AddHeadersFlag(cmd *cobra.Command, headers *[]string)
- func AddIntervalFlag(cmd *cobra.Command, interval *string, def string)
- func AddMethodFlag(cmd *cobra.Command, method *string, def string, usage string)
- func AddOnceFlag(cmd *cobra.Command, once *bool)
- func AddPathFlag(cmd *cobra.Command, path *string, def string, usage string)
- func AddPayloadFlags(cmd *cobra.Command, payload *string, payloadDef string, mime *string, ...)
- func AddSeedFlag(cmd *cobra.Command, seed *int64)
- func AddServerFlag(cmd *cobra.Command, server *string, def string, aliases ...string)
- func AddTemplateDelimiterFlags(cmd *cobra.Command, openDelim *string, closeDelim *string)
- func AddTemplateVarFlag(cmd *cobra.Command, vars *[]string)
- func BuildPayload(rawPayload string, mime string) ([]byte, string, error)
- func BuildPayloadWithDelimiters(rawPayload string, mime string, openDelim string, closeDelim string) ([]byte, string, error)
- func EncodeCBORFromJSON(jsonStr string) ([]byte, error)
- func GuessMIME(body []byte) string
- func Logger() *slog.Logger
- func ParseHeaders(headers []string) (map[string]string, error)
- func ParseHeadersWithDelimiters(headers []string, openDelim string, closeDelim string) (map[string]string, error)
- func ParseTemplateVars(vars []string) (map[string]string, error)
- func PrettyBodyByMIME(mime string, body []byte) []byte
- func PrintColoredMessage(title string, sections []MessageSection, body []byte, mime string)
- func PrintError(format string, args ...interface{})
- func PrintHeader(format string, args ...interface{})
- func PrintInfo(format string, args ...interface{})
- func PrintKeyValue(key string, value interface{})
- func PrintSuccess(format string, args ...interface{})
- func PrintWarning(format string, args ...interface{})
- type KV
- type MessageSection
Constants ¶
const ( CTJSON = "application/json" CTCBOR = "application/cbor" CTText = "text/plain" )
Variables ¶
This section is empty.
Functions ¶
func AddAllowFileReadsFlag ¶ added in v1.1.0
AddAllowFileReadsFlag provides a CLI flag to allow using {{file:...}} placeholders. Disabled by default for safety; the CLI flag should be used with care in untrusted environments.
func AddDestFlag ¶
AddDestFlag adds a standardized destination flag (topic/path/subject/channel/table). Supports aliases for backward compatibility.
func AddFileCacheFlag ¶ added in v1.1.0
AddFileCacheFlag adds a --cache-files flag for enabling file content caching. AddFileCacheFlag adds a --cache-files flag for enabling file content caching.
func AddFileRootFlag ¶ added in v1.1.0
AddFileRootFlag adds a --file-root flag to restrict file: placeholder reads.
func AddHeadersFlag ¶
AddHeadersFlag adds a repeatable flag for metadata/headers in key=value format.
func AddIntervalFlag ¶
AddIntervalFlag adds a common interval flag for periodic actions.
func AddMethodFlag ¶
AddMethodFlag adds a common HTTP method flag.
func AddOnceFlag ¶ added in v1.1.0
AddOnceFlag adds a flag to execute the action once and exit.
func AddPathFlag ¶
AddPathFlag adds a common path/resource flag.
func AddPayloadFlags ¶
func AddPayloadFlags(cmd *cobra.Command, payload *string, payloadDef string, mime *string, mimeDef string)
AddPayloadFlags adds payload, mime and testpayload flags.
func AddSeedFlag ¶ added in v1.1.0
AddSeedFlag provides a CLI flag to configure a deterministic seed for test payload generation to make output deterministic during tests or reproducible runs.
func AddServerFlag ¶
AddServerFlag adds a standardized server/broker/connection flag. Supports aliases for backward compatibility (e.g., --address, --broker).
func AddTemplateDelimiterFlags ¶
AddTemplateDelimiterFlags adds flags for customizing template variable delimiters.
func AddTemplateVarFlag ¶ added in v1.1.0
AddTemplateVarFlag adds a repeatable --template-var name=value flag
func BuildPayload ¶
BuildPayload builds request payload bytes and content-type from either a testpayload type or a raw payload with MIME. Priority: if testType is provided, it's used; otherwise raw payload with MIME is used; returns (nil, "") if neither provided. Uses default template delimiters "{{" and "}}".
func BuildPayloadWithDelimiters ¶
func BuildPayloadWithDelimiters(rawPayload string, mime string, openDelim string, closeDelim string) ([]byte, string, error)
BuildPayloadWithDelimiters builds request payload with custom template delimiters. Supports placeholders: {{json}}, {{cbor}}, {{sentiment}}, {{sentence}}, {{datetime}}, {{nowtime}}, {{counter}}, {{file:/path}}
func EncodeCBORFromJSON ¶
EncodeCBORFromJSON parses a JSON string and encodes it as CBOR bytes.
func GuessMIME ¶
GuessMIME tries to guess a content type from raw body. It detects JSON by leading '{' or '[' and CBOR by first byte 0xA0-0xBF/0x80-0x9F/0x60-0x7F heuristics. Falls back to text/plain.
func ParseHeaders ¶
ParseHeaders parses a slice of "key=value" strings into a map. Returns an error if any header is malformed. Uses default template delimiters "{{" and "}}".
func ParseHeadersWithDelimiters ¶
func ParseHeadersWithDelimiters(headers []string, openDelim string, closeDelim string) (map[string]string, error)
ParseHeadersWithDelimiters parses headers with template interpolation using custom delimiters. Header values support template variables like {{nowtime}}, {{counter}}, {{file:/path}}, etc.
func ParseTemplateVars ¶ added in v1.1.0
ParseTemplateVars converts a slice of "name=value" into a map.
func PrettyBodyByMIME ¶
PrettyBodyByMIME pretty-prints JSON/CBOR bodies based on MIME, otherwise returns original body.
func PrintColoredMessage ¶
func PrintColoredMessage(title string, sections []MessageSection, body []byte, mime string)
PrintColoredMessage prints a colored, consistently formatted message with sections and body. Title and section titles are highlighted; items are aligned as key: value; body is pretty-printed by MIME.
func PrintError ¶
func PrintError(format string, args ...interface{})
PrintError prints an error message with color to stderr.
func PrintHeader ¶
func PrintHeader(format string, args ...interface{})
PrintHeader prints a bold header message.
func PrintInfo ¶
func PrintInfo(format string, args ...interface{})
PrintInfo prints an informational message with color.
func PrintKeyValue ¶
func PrintKeyValue(key string, value interface{})
PrintKeyValue prints a key-value pair with color.
func PrintSuccess ¶
func PrintSuccess(format string, args ...interface{})
PrintSuccess prints a success message with color.
func PrintWarning ¶
func PrintWarning(format string, args ...interface{})
PrintWarning prints a warning message with color.
Types ¶
type MessageSection ¶
MessageSection groups related key-value pairs under a titled section.