From a7cf8027414ce600561ce9c03a86e9d38d4f1416 Mon Sep 17 00:00:00 2001 From: Bryan McNulty Date: Mon, 29 Sep 2025 20:10:02 -0500 Subject: [PATCH] add truncate func --- internal/util/util.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/util/util.go b/internal/util/util.go index 5f6c8f3..5daf83f 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -1,10 +1,11 @@ package util import ( - "github.com/google/uuid" "math/rand" // not crypto secure "regexp" "strings" + + "github.com/google/uuid" ) const randHostnameCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-" @@ -24,6 +25,13 @@ func RandomHostname() (hostname string) { } } +func Truncate(s string, n int) string { + if len(s) <= n { + return s + } + return s[:n] + "..." +} + func RandomWindowsTempFile() string { return `\Windows\Temp\` + strings.ToUpper(uuid.New().String()) }