2

Is there any way of printing a struct with mixed value types, including pointer types, such that all value are shown? For example:

package main

import (
    "fmt"
)

type test struct {
  Str string
  Ptr *string
}

func main() {
  s := "some string"
  p := &s

  t := test{
     Str: s,
     Ptr: p,
  }

  fmt.Printf("%#v\n", t)
}

I want something like: main.test{Str:"some string", Ptr:(*string)("some string"}
instead of: main.test{Str:"some string", Ptr:(*string)(0x1040a120)}

https://play.golang.org/p/YkZrPOeQ_Y

1 Answer 1

1

There's no fmt verb you could use for that functionality. You could implement Stringer on your struct and have full control over how the struct is printed.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.