I am studying a sample Go application that stores data in mongodb. The code at this line (https://github.com/zeebo/gostbook/blob/master/context.go#L36) seems to access a user ID stored in a gorilla session:
if uid, ok := sess.Values["user"].(bson.ObjectId); ok {
...
}
Would someone please explain to me the syntax here? I understand that sess.Values["user"]
gets a value from the session, but what is the part that follows? Why is the expression after the dot in parentheses? Is this a function invocation?
if value, ok := try_to_obtain_value(); ok { ...
), and is explained, for instance, in "Effective Go" -- see the section called "Maps". I should add that this whole document is a must read for any wannabe gopher. – Blaeberry