Golang Print Struct Verbosely

2744 단어 beginnersgo


package main

import (
    "fmt"
)

type Foo struct {
    bar Bar
}

type Bar struct {
    number int
    word   string
}

func NewFoo(number int, word string) *Foo {
    return &Foo{Bar{number, word}}
}

func main() {
    f := NewFoo(10, "testing")
    fmt.Printf("%+v\n%#v\n%v", f, f, f)
}



$ go run main.go
&{bar:{number:10 word:testing}}
&main.Foo{bar:main.Bar{number:10, word:"testing"}}
&{{10 testing}}

좋은 웹페이지 즐겨찾기