Skip to content

Functions

Pass by value

  • Go is a pass by value language. It means that when a function is called, the function receives a copy of the argument
  • Any modifications made inside of the function do not affect the original variable outside of the function

Value Types

  • In order to modify the original variable, pointers need to be manually specified by means of & and *

  • Basic Types

  • bool
  • string
  • int (int, int8, int16, int32, int64)
  • uint (uint, uint8, uint16, uint32 uint64 uintptr)
    • byte (alias for uint8)
    • rune (alias for int32 - unicode code point)
  • float (float32, float64)
  • complex (complex64, complex128)

  • Collections

  • struct
  • array

Reference types

  • Reference types are already references to an address in memory. Therefore there is usually no need to manipulate pointers with them, given that both copies point to the same underlying array
  • Slice: has a ptr to head of the actual array, a capacity and a length
  • Map
  • Channel
  • Pointer
  • Function

Function visibility

The naming of symbols in Go dictate the visibility of the symbol

  • PascalCase is used for exported functions/symbols. Can be accessed from other packages.
  • camelCase for internal functions. Only visible for the current package.