Append a map

7,152 views
Skip to first unread message

Solar Granulation

unread,
Apr 8, 2011, 12:46:39 PM4/8/11
to golang-nuts
Hi

I was studying Go a few months ago but let it lapse. I've forgotten a
lot in the interim it seems and, now that I have a project that I want
to undertake in Go, I'm having trouble finding my way to conclusions
on some points. The question that I'm going to ask is probably
preposterous, but coming to understand this will aide my return to the
language, I think.

It would be really nice for the project if I could use a dynamically
sized map object. I'd like to be able to declare the map in the style
of:
things map[string]thing{}
and then add to that map during the processing of an XML file. My
first thought was to use the slice append approach, I'm trying to
figure out if I can use something like
things []map[string]thing{}
things = append(things, ["key"]thing-value)
is something like this possible?

Whatever the solution it needs to fit into a custom type, as well.
I'm now wondering about built-in XML functions which I'll go look at,
but I thought there's no harm in posting.

Thanks.

jimmy frasche

unread,
Apr 8, 2011, 1:39:42 PM4/8/11
to Solar Granulation, golang-nuts
Maps are a reference type. Maps are dynamically sized.

things := map[string]thing{}
things["key"] = thing_value

Solar Granulation

unread,
Apr 8, 2011, 1:42:05 PM4/8/11
to golang-nuts
Oh! Fantastic! Thank you very much.
Reply all
Reply to author
Forward
0 new messages