O'Reilly logo

The Go Programming Language Phrasebook by David Chisnall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

15. Interacting with the Go Runtime

One of the advantages of a dynamic language is that the internals of the implementation are exposed for your use. This lets you do various metaprogramming things that are much harder in static languages. The go package and its subpackages let you do very complex metaprogramming by transforming the abstract syntax tree of a Go program, but even without going that deep into the implementation there are lots of interesting things that you can do.

Finding the Type of a Variable

 8  switch t.Kind() { 9    case reflect.Int, reflect.Uint,10       reflect.Int8, reflect.Int16,11       reflect.Int32, reflect.Int64,12       reflect.Uint8, reflect.Uint16,13       reflect.Uint32, reflect.Uint64, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required