Instead of using strings.HasPrefix
and manual slicing, use the
strings.TrimPrefix
function. The original string will be returned
if the string doesn't start with the prefix.
Using strings.TrimPrefix
is idiomatic for trimming and avoids mistakes such as
off-by-one.
if strings.HasPrefix(str, prefix) {
str = str[len(prefix):]
}
str = strings.TrimPrefix(str, prefix)