tags:

views:

77

answers:

4

I'm looking for something like PHP's print_r or python's dict. Anybody know if this function exists, or its something that needs to be implemented?

+3  A: 

There is a reflect package in go.
You can find solution to your problem in the following article.

Li0liQ
+1  A: 

For printing native go objects, like maps, slices, and arrays, you can try:

fmt.Printf("%v", object)

However there isn't a general method to do it with user-defined struct types..

marketer
A: 

Try

fmt.Printf("%+v", object)

That might give you something resembling what you want.

Evan Shaw
+1  A: 

You can try using the package dump, which acts similar to PHP's print_r or var_dump.

The sources are here and the main project page is here.

Then just call dump.Dump(yourObject) or dump.Fdump(file, yourObject)

yuku