The go language requires the conversion to be displayed between different types. Conversions are divided into type conversions and interface conversions.
The idea of type conversion is:
The X type needs to be converted to the Y type, and the syntax is T (x). If you are unsure of the priority of some place, you can add () the constraint yourself to (T) (X). Such as:
*point (P)//and * (Point (P))
(*point) (p)//p converted to *point
(Func ()) (x)//x converted to UNC ()
(func () int) (x)//x convert func () int
Interface conversions
For example, there are 2 types of interfaces:
Type IA Interface {}
Type IB Interface {Foo ()}
IA to convert to IB:
var a A
var B = A. (b)
IB conversions like IA:
var b b
var a = a (b)
The difference between the above two conversions:
1. First realize that IB has a more than Ia method foo (), which is a subset of IA.
2, IA to IB, is from the general to the special conversion, not necessarily can succeed, so use assert a. (B), from the literal meaning of the word "assertion", it is understandable to "judge", not necessarily to succeed.
3, IB into IA, is a special to the general transformation, direct a (b) forced conversion can be.
The conversion between basic types such as String,int,bool in Go requires a StrConv package.
Official Document Address: http://golang.org/pkg/strconv/
Check the documentation when you use it.
Type conversion of Go language