Skip to content

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

@apxamccallum

Description

@apxamccallum

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

sessions/doc.go

Lines 140 to 145 in bb4cd60

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

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions