From 88f785414f5d603113222e2b0ba8f96143c350f8 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Wed, 6 Dec 2023 21:52:29 +0100 Subject: [PATCH] feat: add helper function to ensure string prefix (#39) --- template/template.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/template/template.go b/template/template.go index d1d6bb6..b715f55 100644 --- a/template/template.go +++ b/template/template.go @@ -77,3 +77,16 @@ func RenderTrim(ctx context.Context, client http.Client, template string, playlo return strings.Trim(out, " \n"), err } + +// AddPrefix is a helper function to ensure a string has a defined prefix. +func AddPrefix(prefix, input string) string { + if strings.TrimSpace(input) == "" { + return input + } + + if strings.HasPrefix(input, prefix) { + return input + } + + return prefix + input +}