Finding variable names with a given string length

This subsection will present another practical example that will be more advanced than the one presented in varTimes.go. You will see how to find the variable names with a given string length – you can use any string length you want. Additionally, the program will be able to differentiate between global variables and local variables.

A local variable is defined inside a function whereas a global variable is defined outside of a function. Global variables are also called package variables.

The name of the utility is varSize.go and it will be presented in four parts. The first part of varSize.go is as follows:

package main import ( "fmt" "go/ast" "go/parser" "go/token" "os" "strconv" ) var ...

Get Mastering Go - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.