Better formatting of struct literals

168 views
Skip to first unread message

Eric Lindsey

unread,
Oct 26, 2020, 12:27:23 PM10/26/20
to golang-nuts
Recently, I gofmt'ed a block of code in a file and this is what I ended up with:

embed := &discordgo.MessageEmbed{
    Color: MembershipEmbedColor,
    Description: "This collection is empty.\n" +
        "Send an image or image URL to get started.",
    Footer: &discordgo.MessageEmbedFooter{Text: "Membership"},
}


I would suggest that it would be more readable to format it thus:

embed := &discordgo.MessageEmbed{
    Color:       MembershipEmbedColor,
    Description: "This collection is empty.\n" +
                 "Send an image or image URL to get started.",
    Footer:      &discordgo.MessageEmbedFooter{Text: "Membership"},
}

This would follow the style of formatting that gofmt uses for struct definitions. Aligning the second line of the continued string would be a special case; I personally haven't seen gofmt do that anywhere else, yet.

I hope this is the right place to file suggestions for gofmt. If not, please send me in the right direction.

Thanks,
Eric

David Skinner

unread,
Oct 27, 2020, 6:52:27 AM10/27/20
to golang-nuts
I very much like things that improve readability.
Reply all
Reply to author
Forward
0 new messages