In Go std lib there're some way to pretty printing object into a Go-Syntax representation, for example,here'd how to pretty print a value,
https://play.golang.org/p/hztlPEf1If
so is there any way to dump definition of a type? If no, what's the challenges behind to stop having this feature.
I write little reflection function that maybe it help you. Please check :
package main
import (
"fmt"
"reflect"
)
type S struct {
A string
B int
c bool
d float64
e struct {
f int
}
}
func main() {
var s S
MagicPrint(&s)
}
func MagicPrint(t interface{}) {
typeOfT := reflect.TypeOf(t).Elem()
fmt.Println("type", typeOfT.Name(), " struct {")
for i := 0; i < typeOfT.NumField(); i++ {
f := typeOfT.Field(i)
fmt.Printf("%s %s
", f.Name, f.Type)
}
fmt.Println("}")
}
Check in Go Playground