golang 转换为字符串_在Golang中,如何将错误转换为字符串?
golang 转换为字符串
In Golang, fmt.Println(err)
can print out the error err
. But how to convert an error to a string explicitely?
在Golang中, fmt.Println(err)
可以打印出错误 err
。 但是如何将错误显式转换为字符串 ?
In Go, the error
type has an interface
在Go中, error
类型具有接口
type error interface {
Error() string
}
Ref: https://golang.org/pkg/builtin/#error
参考: https : //golang.org/pkg/builtin/#error
So, for an error err
, you can call
因此,对于错误err
,您可以致电
err.Error()
to get a string representing err
.
得到一个表示err
的字符串。
翻译自: https://www.systutorials.com/in-golang-how-to-convert-an-error-to-a-string/
golang 转换为字符串
您可能感兴趣的文章:
Golang 标准库:strconv 包的应用
Go安装、变量声明、strings模块
php字符串函数有哪些
未结束的字符串常量怎么解决
js 未结束的字符串常量错误怎么解决
控讨:Javascript 强制类型转换
js字符串数组相互转换
php数字类型之字符串类型详解
Golang string
Python字符串详解