0
0
mirror of https://github.com/thegeeklab/wp-plugin-go.git synced 2024-11-25 09:30:39 +00:00

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

View File

@ -77,3 +77,16 @@ func RenderTrim(ctx context.Context, client http.Client, template string, playlo
return strings.Trim(out, " \n"), err 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
}