Course: Learning GO

A collection of go basic fundamentals, syntax and concepts.

Table of contents

Lesson: Package and Visibility

Package

  • A package is a group of files in the same folder.
  • We can define the name at the top.
  • We can import other packages.
package main

import "fmt"

func main(){
    fmt.Println("Hello Go!")
}

Go compiler only sees package not files

If the name starts with uppercase it is public if it is lowercase it is private to that package
PrintData() - public - will be exported from package
printData() - private

Visibility

What we write in a module

  • if it’s camelCase, it’s private
  • if it’s TitleCase, it’s public and exported

Variables and lambda functions can be:

  • module scoped
  • function scoped
  • block scoped
package main

import "fmt"

func notExported(){

}

func Exported(){

}