utf8.DecodeRuneInString
instead of []rune(string)[0]
GO-P4006It is recommended to use utf8.DecodeRuneInString
instead of
[]rune(string)[0]
to prevent unwanted rune
slice allocation.
package main
func getFirstRune(s string) rune {
r := []rune(s)[0]
return r
}
package main
import (
"unicode/utf8"
)
func getFirstRune(s string) rune {
r, _ := utf8.DecodeRuneInString(s)
return r
}