Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:25
Show Gist options
  • Select an option

  • Save dacr/ea48f376befb8b842419a9cb047a1ec7 to your computer and use it in GitHub Desktop.

Select an option

Save dacr/ea48f376befb8b842419a9cb047a1ec7 to your computer and use it in GitHub Desktop.
go shadowing / published by https://github.com/dacr/code-examples-manager #928f07eb-e5e7-4bdc-859c-ddf0dc3fd729/c2af55597758b1d5d6e62a16dd736452ed138def
/*?sr/bin/true; exec /usr/bin/env nix-shell -p go --run "go run $0" #*/
// summary : go shadowing
// keywords : go, shadowing, @testable
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : 928f07eb-e5e7-4bdc-859c-ddf0dc3fd729
// created-on : 2025-03-27T10:46:26+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : nix-shell -p go --run "go run $file"
package main
import (
"fmt"
)
func shadowingExample() {
toto := "toto"
if true {
//toto = "titi" // change the upper variable
toto := "titi" // new toto variable ! shadowing the previous one
fmt.Println(toto)
}
fmt.Println(toto)
}
func main() {
shadowingExample()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment