Beginning a Journey to Go land

I’m just beginning to learn Go coming from a background where I write mainly JavaScript and Java code on a daily basis.

I’ll try to document the learning resources I’m utilizing as well as the road blocks I’ll face along the way.

Learning Resources



Running a sample application

Following some code samples presented in A Tour of Go I ran the example where Russ Cox demonstrated the power of Reflection.

To run Go on my environment I’m utilizing docker

  • docker run -t -i -p 6000:6000 diogogmt/golang:1.4.2 /bin/bash


import (

type Lang struct {
  Name string
  Year int
  URL string

func main() {
  start := time.Now()
  do(func(lang Lang) {
    count(lang.Name, lang.URL)
  fmt.Printf("%.2fs total\n", time.Since(start).Seconds())

func do(f func(Lang)) {
  input, err := os.Open("/root/lang.json")
  if err != nil {
  dec := json.NewDecoder(input)
  for {
    var lang Lang
    err := dec.Decode(&lang)
    if err != nil {
      if err == io.EOF {

func count(name, url string) {
  start := time.Now()
  r, err := http.Get(url)
  if err != nil {
    fmt.Printf("%s: %s", name, err)
  n, _ := io.Copy(ioutil.Discard, r.Body)
  fmt.Printf("%s %d [%.2fs]\n", name, n, time.Since(start).Seconds())


{"Name": "Erlang", "Year": 1986, "URL": ""}
{"Name": "PHP", "Year": 1995, "URL": ""}
{"Name": "Scala", "Year": 2003, "URL": ""}
{"Name": "Go", "Year": 2009, "URL": ""}

Running the program: go install tour && tour


  • Shift from an object oriented hierarchical to functional based way of thinking
  • Using case notation to define private and public functions – functions starting with upper case letters are exported
  • Declaring and assigning a value to a variable using the := notation
  • Type inference when declaring variables which makes the language feel really dynamic
  • Descriptive error messages informing compilation problems
  • No parenthesis in control structures
  • Support for providing functions as arguments to functions which reminds me much of JavaScript
  • Very clear way to download and import packages to a project
  • Focus on testing and documentation at a language level

Next I’ll be continuing with the examples in the Tour of Go video and add some concurrency features to the little web crawler listed above