feat: add helper function to ensure string prefix (#39)

This commit is contained in:
Robert Kaussow 2023-12-06 21:52:29 +01:00 committed by GitHub
parent 1e98790015
commit 88f785414f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 0 deletions

View File

@ -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
}