On Thu, Jun 6, 2019 at 10:56 AM ajs via golang-nuts <golang-nuts@googlegroups.com> wrote: > > I can declare literal bar inside a function like this: > > func foo() { > bar := []struct{a, b, c string} { > { "really", "long", "row"}, > { "many", "many", "rows"}, > ... > } > } > > But I really want it anchored (for code generation reason) outside of a > function like this: > > func foo() { > ... > } > > var bar []struct{a, b, c string} { > { "really", "long", "row"}, > { "many", "many", "rows"}, > ... > } > > The problem is it gets upset on the last character of the 'var bar ...' line. > Is there a better way to write this? > Note for reasons outside of this discussion, I really want to avoid writing > it by repeating the discrete field names: > > var bar []struct{a, b, c string} { > {a: "really",b: "long",c: "row"}, // Don't want to do this > {a: "many", b: "many", c: "rows"}, // Don't want to do this > ... > } > > Any thoughts? What am I missing?
An important tip: when asking a question, please tell us precisely what you did and precisely what happened. You can see what happened, but when you write "it gets upset" we have to guess. And it's easy for us to guess wrong. When I look at var bar []struct{a, b, c string} { { "really", "long", "row"}, { "many", "many", "rows"}, ... } what I think is that it should say var bar = []struct{... That is, you are missing the "=". But I don't know if that was a typo in the e-mail message. So if that doesn't help tell us exactly what you did and exactly what happened. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUrcaDVSCEt-MeeZQ8CqZbp4vpDZ35jLu8Pu%2BmDjcwupw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.