March 2020
Intermediate to advanced
406 pages
8h 39m
English
A kind is used as a placeholder to define the kind of type that a specific type represents. It is used to denote what the type is made of. This is very useful in determining what sort of structure has been defined. Let's look at an example:
package mainimport ( "fmt" "reflect")func main() { i := []string{"foo", "bar", "baz"} ti := reflect.TypeOf(i) fmt.Println(ti.Kind())}
In our example, we can see that we have created a slice of strings – foo, bar, and baz. From there, we can use reflection to find the type of i, and we can use the Kind() function to determine what the type is made of—in our case, a slice as follows:

This can be useful ...
Read now
Unlock full access