package main import ( "fmt" ) type Person struct { Name string Age int Email string } func main() { p := Person{ Name: "Drake", Age: 35, Email: "drake@example.com", } fmt.Println(p) fmt.Println("------------------------------------------------------------") fmt.Printf("%+v\n", p) fmt.Println("------------------------------------------------------------") fmt.Printf("%#v\n", p) fmt.Println("------------------------------------------------------------") fmt.Printf("%# v\n", p) }
zzh@ZZHPC:/zdata/MyPrograms/Go/study$ go run main.go {Drake 35 drake@example.com} ------------------------------------------------------------ {Name:Drake Age:35 Email:drake@example.com} ------------------------------------------------------------ main.Person{Name:"Drake", Age:35, Email:"drake@example.com"} ------------------------------------------------------------ main.Person{Name:"Drake", Age: 35, Email:"drake@example.com"}
Pretty look:
package main import ( "encoding/json" "fmt" ) func main() { type Person struct { Name string Age int Email string } p := Person{ Name: "Drake", Age: 35, Email: "drake@example.com", } bs, _ := json.MarshalIndent(p, "", "\t") fmt.Println(string(bs)) }
zzh@ZZHPC:/zdata/MyPrograms/Go/study$ go run main.go { "Name": "Drake", "Age": 35, "Email": "drake@example.com" }