Scopes in Go

Same name cannot be declared again inside a same scope. There are following types of scopes in Go:

  1. package: Each Go package has it’s own scope. For e.g. declared funcs are only visible to the files belonging to same package.
  2. file: Imported packages are only visible to the importing file. Each file has to import external packages on it’s own.
  3. func.
  4. block.