I encountered many times the following scenario:
func First(s string, n int) string {
if len(s) <= n {
return s
}
return s[:n]
}
This simple function try to get at most N-bytes from a string. Likewise, for at most N-bytes "tail" from a string:
func Last(s string, n int) string {
if len(s) <= n {
return s
}
return s[len(s)-n:]
}
These functions will many some programs easier to read, like the TrimPrefix/TrimSuffix functions.