DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in

[memo] Debug values at Golang

#go

I forget these.

package main

import (
    "github.com/davecgh/go-spew/spew"
    "log"
)

type Name struct {
    FirstName string
    LastName  string
}

type Address struct {
    Country    string
    PostalCode string
    Address    string
}

type Person struct {
    Name    Name
    Address Address
}

func main() {
    person := &Person{
        Name{"Cynthia", "Stone"},
        Address{"us", "02110", "1091 Lyon Avenue, Boston"},
    }

    log.Printf("[debug] %+v", person)

    log.Print("[debug] Humanize Output")
    spew.Dump(person)
}

execute output :

2009/11/10 23:00:00 [debug] &{Name:{FirstName:Cynthia LastName:Stone} Address:{Country:us PostalCode:02110 Address:1091 Lyon Avenue, Boston}}
2009/11/10 23:00:00 [debug] Humanize Output
(*main.Person)(0xc0000c6140)({
 Name: (main.Name) {
  FirstName: (string) (len=7) "Cynthia",
  LastName: (string) (len=5) "Stone"
 },
 Address: (main.Address) {
  Country: (string) (len=2) "us",
  PostalCode: (string) (len=5) "02110",
  Address: (string) (len=24) "1091 Lyon Avenue, Boston"
 }
})

see : Go่จ€่ชžใงPHPใฎvar_dumpใ‚„JavaScriptใฎconsole.log็š„ใชใ‚‚ใฎ -- Qiita

Top comments (0)

๐Ÿ— We built a 100% open source community software called Forem.

You can contribute to the codebase or host your own.