Prefix Unexported Globals with _

Prefix unexported top-level vars and consts with _ to make it clear whenthey are used that they are global symbols.

Exception: Unexported error values, which should be prefixed with err.

Rationale: Top-level variables and constants have a package scope. Using ageneric name makes it easy to accidentally use the wrong value in a differentfile.

BadGood
  1. // foo.go
  2.  
  3. const (
  4. defaultPort = 8080
  5. defaultUser = "user"
  6. )
  7.  
  8. // bar.go
  9.  
  10. func Bar() {
  11. defaultPort := 9090
  12. fmt.Println("Default port", defaultPort)
  13.  
  14. // We will not see a compile error if the first line of
  15. // Bar() is deleted.
  16. }
  1. // foo.go
  2.  
  3. const (
  4. _defaultPort = 8080
  5. _defaultUser = "user"
  6. )