Good practice - 3

Error

  • How to stop a program when an error occurs:

    if err != nil {
    fmt.Printf("Program stopping with error %v", err)
    os.Exit(1)
    }
    // OR :
    if err != nil {
    panic("ERROR occurred: " + err.Error())
    }
    

Performance best practices and advice

  • Use the initializing declaration form := wherever possible (in functions).
  • Use bytes if possible instead of strings
  • Use slices instead of arrays.
  • Use arrays or slices instead of a map where possible (see ref. 15)
  • Use for range over a slice if you only need the value and not the index; this is slightly faster than having to do a slice lookup for every element.
  • When the array is sparse (containing many 0 or nil-values), using a map can result in lower memory consumption.
  • Specify an initial capacity for maps.
  • When defining methods: use a pointer to a type (struct) as a receiver.
  • Use constants or flags to extract constant values from the code.
  • Use caching whenever possible when large amounts of memory are being allocated.
  • Use template caching

/dev/sda1=snap-0f75ee322dbe2249e:70:false:gp2, xvdf=snap-0c12b9ad6e4346898:50:false:gp2:encrypted, xvdg=snap-04ece5bba81647e22:100:false:gp2, xvdc=snap-0096b6863670d38de:150:false:gp2:encrypted