March 2020
Intermediate to advanced
406 pages
8h 39m
English
Being able to tell the type of a variable is important in Go. In our example, we can validate the fact that a string type is, in fact, a string, as shown in the following code block:
package mainimport ( "fmt" "reflect")func main() { var foo string = "Hi Go!" fooType := reflect.TypeOf(foo) fmt.Println("Foo type: ", fooType)}
The output from our program will show us that the reflection type will accurately derive the foo string type:

Although this example is simple, it's important to understand the underlying principle: if, instead of validating the string, we are looking at an incoming network call or the return from an external library ...
Read now
Unlock full access