Golang initializing an array of struct bodies

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Recent group of new project requirements with go to write, no way can only read the document side write code, today encountered depressed problem, check for a long time finally found incredibly is a punctuation caused, hence the record of

Just write unit tests for an interface to initialize a struct array, then iterate over the array and establish HTTP. Request for testing, the results have been error, and finally ... The correct posture of Golang structure initialization was found t_t

1Requests: =[]authrequest{2 authrequest{3             "Plain",4             "xl_test@xunlei.net",5             "123456",6             "SMTP",7             3,8             "192.168.34.104",9             "client.example.com",Ten         }, One authrequest{ A             "Plain", -             "xl_test@xunlei.net", -             "123456", the             "POP3", -             3, -             "192.168.34.104", -             "client.example.com", +         }, -}

The problem is that the last element in the curly brace must be followed by a comma, and Golang's strict syntax is a taste.

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.