Errors

An Introduction to Errors

Errors are treated as values in Go. The error type is a built-in interface. An error variable represents any value that can describe itself as a string.

 type error interface {
    Error() string
 }

Functions often return an error value, and calling code should handle errors by testing whether the error equals nil.

i, err := strconv.Atoi("42")
if err != nil {
    fmt.Printf("couldn't convert number: %v\n", err)
    return
}
fmt.Println("Converted integer:", i)

Maps

An Introduction to Maps.

Maps

Maps are Go’s built-in associative data type (sometimes called hashes or dicts in other languages). Maps are made up of key-value pairs and provide a way to store data without relying on indexing.

``` package main

Continue reading Maps

Goroutines

An Introduction to Goroutines.

# Goroutines

A goroutine is a lightweight thread managed by the Go runtime. go f(x, y, z) starts a new goroutine running f(x, y, z) The evaluation of f, x, y, and z happens in the current goroutine and the execution of f happens in the new goroutine. Goroutines run in the same address space, so access to shared memory must be synchronized

Things that make Go fast

Summary of the important concepts from Dave Cheney’s talk at Gocon, 2014.

One of the design goals of Go was fast compilation. But How is it achieved? Dave Cheney’s talk at Gocon, a fantastic Go conference held semi-annually in Tokyo, Japan, 2014 covers 5 things that makes Go fast.

#1 Go’s efficient treatment and storage of values.

var gocon int32 = 2014

This is an example of a value in Go. When compiled, gocon consumes exactly four bytes of memory. Let’s compare Go with some other languages:

Pagination