This is a created
article in which the information may have evolved or changed.
(Go mailing list problem record 1)
How can I get a struct size?
How go gets the structure size
Encoding/binary. Size can only report the encoded size under very strict circumstances. You probably want something like unsafe. Sizeof
The reflect. Type.size () can ' t calculate slice struct.
The person here asks the structure is a common head+data structure of the message, want to send through the socket, need to get the length, but the data structure has slice.
- It was proposed to use reflect. Type.size (), but this method does not get the slice size
- Then you can use Encoding/binary. Size. But slice this should be a pointer? So what you get is actually a pointer that contains slice, not the size of the slice content ...
Go get CMD output in real time
How does go get the real-time output of call cmd?
https://golang.org/pkg/os/exec/#Cmd. Stdoutpipe