Golang Print Struct Verbosely

sunday-snippet · May 8, 2022 · ~1 min
Sunday Snippet #16 golang print struct verbosely
Sunday Snippet #16 golang print struct verbosely
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)
}
1
2
3
4
$ go run main.go
&{bar:{number:10 word:testing}}
&main.Foo{bar:main.Bar{number:10, word:"testing"}}
&{{10 testing}}
· · ·

Love This Content?

Any kind of supports is greatly appreciated! Kindly support me via Bitcoin, Ko-fi, Trakteer, or just continue to read another content. You can write a response via Webmention and let me know the URL via Telegraph.

Drop Your Comment Below