gorilla / sessions

Package gorilla/sessions provides cookie and filesystem sessions and infrastructure for custom session backends.
https://gorilla.github.io
BSD 3-Clause "New" or "Revised" License
2.93k stars 371 forks source link

[documentation] <Scope Issue in Example Code for retrieval and type-assertion> #283

Open apxamccallum opened 2 days ago

apxamccallum commented 2 days ago

Is there an existing issue for this?

Current Behavior

https://github.com/gorilla/sessions/blob/bb4cd60c952a9ce48ea0dc6cc7b282ff79c38263/doc.go#L140-L145 In this example val.(*Person) will not be assigned to person as it is outside of the if statement scope.

Suggested Correction

// Retrieve our struct and type-assert it
val := session.Values["person"]
person, ok := val.(*Person)
if !ok {
    // Handle the case that it's not an expected type
}