http://play.golang.org/p/joEmjQdMaS
package main
import "fmt"
type SomeStruct struct {
somePointer *somePointer
}
type somePointer struct {
field string
}
func main() {
fmt.Println(SomeStruct{&somePointer{"I want to see what is in here"}})
}
This prints a memory address like this {0x10500168}
Is there a way to make it print:
{{"I want to see what is in here"}}
This is mostly for debugging purposes, if I had a struct with 30 pointer fields, I didn't want to have to do a println for each of the 30 fields to see what is in it.
func (p *SomeStruct) String() string;
for the outerSomeStuct
– Tetrastichfmt.Printf("%+v", SomeStruct{&somePointer{"I want to see what is in here"}})
by using the %+v it prints out all the attributes with their names. If you just do %v it will show only the values – Callus&somePointer{"
– Callus