err to string golang code example
Example 1: interface to string golang
var x interface{} = "abc"
str := fmt.Sprintf("%v", x)
Example 2: go error handling
func doStuff() (int, error) {
}
func main() {
result, err := doStuff()
if err != nil {
// handle error
} else {
// all is good, use result
}
}
Example 3: golang convert rune to string
r := rune('a')
fmt.Println(r, string(r))