Eduardo Piorini retweetledi

Go's most underrated superpower is its parser packages: go/parser, go/token, and go/ast.
It's actually crazy how under-used and under-discussed these packages are.
Basically, your Go code is tokenized and parsed by the compiler to generate something called an abstract syntax tree (AST), so that it can compile into IR which is then translated into machine code.
The go/parser package parses Go code and allows you to correctly identify everything about a Go file: imports, comments, functions, types, variables, and more.
The beauty of this is that it allows for incredible boilerplate automation since you literally have the language's parser built in!
For example, you can generate DTO structs from models with JSON tags. If you tried to do this manually using only if statements and loops, your code would be full of bugs, and a robust implementation would require building an actual Go code parser. Fortunately, in Go, you can use the standard library to parse Go files, extract all types, and generate the DTOs

English




























