Skip to content

Latest commit

 

History

History
3460 lines (2598 loc) · 61.4 KB

slides.md

File metadata and controls

3460 lines (2598 loc) · 61.4 KB

Introduction to the Go Programming Language

About me

  • Author, Head First Ruby and Head First Go
  • 4 years experience as online software development instructor
  • See my recent courses at https://teamtreehouse.com

Where to Learn Go

https://tour.golang.org

(We'll repeat that link at the end.)

Another humble recommendation

Why Go?

Go at a glance

  • C-like syntax
  • Compiles to native code
  • Type-safe
  • Garbage collected
  • Concurrency built into language

OK, but what can you do with Go?

Docker

Docker

  • "'go build' will embed everything you need. (No more 'install this in order to run my stuff'.)"
  • "Extensive standard library and data types."
  • "Strong duck typing."

—Jérôme Petazzoni, "Docker and Go: why did we decide to write Docker in Go?"

::: notes

https://www.slideshare.net/jpetazzo/docker-and-go-why-did-we-decide-to-write-docker-in-go

:::

Kubernetes

Kubernetes

  • "Code in Go isn't overly complex. People don't create FactoryFactory objects."
  • "Something with the feel of C with more advanced features like anonymous functions is a great combo."
  • "Garbage Collection: We all know how to clean up after our selves but it is so nice to not have to worry about it."

—Joe Beda, "Kubernetes + Go = Crazy Delicious"

Poll: What do you want to make with Go?

  1. A system utility
  2. A web app or service
  3. Something else entirely
  4. I don't know yet

Go Tools

"go fmt"

  • Automatically fixes code style
  • Acts as community's style guide
  • No more arguing tabs vs. spaces!

"go fmt"

Before

package main

import "fmt"

func main() {
repeatLine("hello", 3     )
}

func repeatLine( line string ,times  int) {
	for i := 0; i < times; i++ {
fmt.Println(line)
	}
}

"go fmt"

$ go fmt repeat.go

"go fmt"

After

package main

import "fmt"

func main() {
	repeatLine("hello", 3)
}

func repeatLine(line string, times int) {
	for i := 0; i < times; i++ {
		fmt.Println(line)
	}
}

"go run"

  • Compiles a Go source file and runs it
  • No executable is saved
$ go run repeat.go
hello
hello
hello

"go build"

  • Compiles Go source file(s) into an executable
$ go build repeat.go
$ ls -l
total 2064
-rwxr-xr-x 1 jay staff 2106512 May  1 21:13 repeat
-rw-r--r-- 1 jay staff     166 May  1 21:13 repeat.go
$ ./