Go

go get github.com/agentfirstkit/agent-first-data/go
package main

import (
    "fmt"

    afdata "github.com/agentfirstkit/agent-first-data/go"
)

func main() {
    event := afdata.NewJSONResult(map[string]any{
        "api_key_secret": "sk-123",
        "latency_ms": 1280,
        "db_url": "postgres://user:p@ss@db/app?token_secret=abc",
    }).Build()
    value := event.Value()

    options := afdata.OutputOptions{}
    fmt.Println(afdata.Render(value, afdata.OutputFormatJson, options))
    fmt.Println(afdata.Render(value, afdata.OutputFormatPlain, options))
}

Useful names use Go casing: Render (the single value × format × options → string entry point), OutputFormat, OutputTo, OutputOptions, OutputOptionsForPolicy, RedactedValue, RedactURLSecrets, RedactURLsInText, RedactArgv, NormalizeUTCOffset, IsValidRFC3339Date, IsValidRFC3339Time, IsValidRFC3339, IsValidBCP47, CliParseOutput, CliParseLogFilters, ParseOutputTo, CliEmitter, BuildCLIError, BuildCliVersion, CliRenderVersion, ValidateProtocolEvent, and DecodeProtocolEvent.

Scoped redaction and extra secret names use the Redactor struct:

r := afdata.Redactor{
    SecretNames: []string{"authorization"},
    URLNames: []string{"url", "relays"},
}
fmt.Println(afdata.Render(r.Value(value), afdata.OutputFormatJson, afdata.OutputOptions{}))
fmt.Println(r.URL("https://api.example.com/?authorization=abc"))
fmt.Println(r.URLsInText("see https://api.example.com/?authorization=abc"))

Behavior Notes

Reference