mercredi 6 octobre 2021

Golang: How do I print the content of the current package (vars, funcs, ...)?

How do I print the content of the current package (vars, funcs, ...)?

In other words, I want to print what an IDE could show me.

For example, given this scenario:

file1.go

package main

var myVar1 = "foo"
var myVar2 = true
var myVar3 = 5

var myVarU1 string
var myVarU2 bool
var myVarU3 int

func aMessyFunc() {
   // something weird
}

var OtherVar1 = "asdf"
var OtherVar2 = false
var OtherVar3 = 9

func OtherMessyFunc() {
   // something weird
}

// some other stuffs

file2.go

package main

var mainVar1 = "hello"
var mainVar2 = "bye"

func main() {
   myAwesomeFunc()
}

I want my stdout be something like this:

'myVar1' (string) has value: "foo"
'myVar2' (bool) has value: true
'myVar3' (int) has value: 5

'myVarU1' (string) has no value
'myVarU2' (bool) has no value
'myVarU3' (int) has no value

'OtherVar1' (string) has value: "asdf"
'OtherVar2' (bool) has value: false
'OtherVar3' (int) has value: 9

'mainVar1' (string) has value: "hello"
'mainVar2' (string) has value: "bye"

'aMessyFunc()'
'OtherMessyFunc()'
'main()'

... // some other stuffs

Note: The files belong to the same package and them can be very messy

Is it posible to achieve something like that?

Is there any useful module|package to do this?

I don't want to treat the whole project like a bunch of text files and parse them one by one

Greetings from Chile (đŸ‡šđŸ‡±) and thanks!





Aucun commentaire:

Enregistrer un commentaire