1

I am doing an inventory of all log statements in my Go application. Since the log statements will contain just variable names, a simple grep is not of use. I want to identify the variable "type" in each log statement and if its a struct, the field names in that struct. I want to write a script to do this.

Is it possible to extract such information using reflections or by any other means in Go?

TechCrunch
  • 2,924
  • 5
  • 45
  • 79
  • 3
    Reflection is runtime by definition. You can probably do this using [parser](https://golang.org/pkg/go/parser/). – Adrian Feb 22 '18 at 14:06
  • 3
    Yes, it's possible. Parsing `.go` files (or any Go source text) is implemented in the standard library itself. Take a look at the [`go/parser`](https://golang.org/pkg/go/parser/) package. – icza Feb 22 '18 at 14:06
  • See also https://godoc.org/go/types. – Charlie Tumahai Feb 22 '18 at 14:12

0 Answers0