I know about ToUpper and ToLower from strings package but obviously they won't help here. Is there a built-in function or do I have to write one myself?
You need to write one yourself, but the building blocks are already in the standard library:
func swapCase(s string) string {
return strings.Map(func(r rune) rune {
switch {
case unicode.IsLower(r):
return unicode.ToUpper(r)
case unicode.IsUpper(r):
return unicode.ToLower(r)
}
return r
}, s)
}