Skip to content

Commit a7cf802

Browse files
committed
add truncate func
1 parent ef53796 commit a7cf802

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

internal/util/util.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package util
22

33
import (
4-
"github.com/google/uuid"
54
"math/rand" // not crypto secure
65
"regexp"
76
"strings"
7+
8+
"github.com/google/uuid"
89
)
910

1011
const randHostnameCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"
@@ -24,6 +25,13 @@ func RandomHostname() (hostname string) {
2425
}
2526
}
2627

28+
func Truncate(s string, n int) string {
29+
if len(s) <= n {
30+
return s
31+
}
32+
return s[:n] + "..."
33+
}
34+
2735
func RandomWindowsTempFile() string {
2836
return `\Windows\Temp\` + strings.ToUpper(uuid.New().String())
2937
}

0 commit comments

Comments
 (0)