DEV Community

Clavin June
Clavin June

Posted on • Originally published at clavinjune.dev on

1 1

Golang Print Struct Verbosely

Sunday Snippet #16 golang print struct verbosely

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)
}
Enter fullscreen mode Exit fullscreen mode
$ go run main.go
&{bar:{number:10 word:testing}}
&main.Foo{bar:main.Bar{number:10, word:"testing"}}
&{{10 testing}}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay