Go mailing list problem record 1

Source: Internet
Author: User
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.

  1. It was proposed to use reflect. Type.size (), but this method does not get the slice size
  2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.