How to Use If with a Short Statement in Go

Use the := operator inside the if statement's initialization clause to declare a variable scoped only to that block.

Use the short variable declaration operator := inside the if statement's initialization clause to declare and initialize a variable that is only visible within the if block.

if err := myFunc(); err != nil {
    log.Fatal(err)
}

This pattern keeps the scope of err limited to the if statement, preventing it from leaking into the outer function scope.