Skip to content

Instantly share code, notes, and snippets.

@inancgumus
Last active October 10, 2017 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inancgumus/3ca06a0af9ebe9abc9a636a2c7754805 to your computer and use it in GitHub Desktop.
Save inancgumus/3ca06a0af9ebe9abc9a636a2c7754805 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
// visible inside main package
const packageLevelConst = 1
// visible everywhere
const ExportedPackageLevelConst = 2
func main() {
// only available to main func
const funcLevelConst = 4
// shadowing the const at line #8
const packageLevelConst = 8
// shadowing the const at line #11
const ExportedPackageLevelConst = 16
fmt.Println("funcLevelConst:", funcLevelConst)
fmt.Println("packageLevelConst:", packageLevelConst)
fmt.Println("ExportedPackageLevelConst:", ExportedPackageLevelConst)
fmt.Println("\nWITHOUT SHADOWING:")
printWithoutShadowing()
}
// this doesn't shadow the constants at lines #8 and #11
func printWithoutShadowing() {
fmt.Println("packageLevelConst:", packageLevelConst)
fmt.Println("ExportedPackageLevelConst:", ExportedPackageLevelConst)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment