如何访问指向Struct的指针的值?

I've got a variable which is equal to a pointer of the following struct:

type Conn struct {
  rwc io.ReadWriteCloser
  l   sync.Mutex
  buf *bytes.Buffer
}

Thus

fmt.Printf("---*cn: %+v
", *cn)

returns

{rwc:0xc42000e080 l:{state:0 sema:0} buf:0xc42005db20}

How can I see the value at the addresses 0xc42000e080 and 0xc42005db20?

My end goal is to inspect this because it's used when connecting to memcache and on the chance memcache breaks I'm trying to reestablish connection, and need to inspect this to solve it.

I am not sure why would you need a separate library for this. The straight forward answer is that you can directly dereference rwc inside the struct.

So, you would do something like

fmt.Printf("---*cn: %+v
", *(cn.rwc))

Assuming Conn is imported and you don't have access to the unexported fields with the standard selector expression you can use the reflect package to bypass that limitation.

rv := reflect.ValueOf(cn)
fmt.Println(rv.FieldByName("buf").Elem())

https://play.golang.org/p/-6lWi1vYod

You can use Render function in https://github.com/luci/go-render package instead of taking the value of the pointer by using * which will crash if the pointer is nil.

just import the library then:

fmt.Printf("Connection: %v", render.Render(<your variable>))