[Book] Learning Go

First Post:

Last Update:

Word Count:
230

Read Time:
1 min

El libro

Introduction

This article is used to keep notes and summaries of the book “Learning Go”.
The content will be continuously updated as I read through the book.

Chapter.1 - Setting Up Your Go Environment

The go command

1
2
3
4
5
6
7
package main

import "fmt"

func main() {
fmt.Println("Hello, world!")
}
1
> go run hello.go
1
> go build hello.go

This creates an executable called hello (or hello.exe on Windows) in the current directory.

Makefiles

Here’s a sample Makefile to add to our very simple project:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
.DEFAULT_GOAL := build

fmt:
go fmt ./...
.PHONY:fmt

lint: fmt
golint ./...
.PHONY: lint

vet: fmt
go vet ./...
.PHONY:vet

build: vet
go build hello.go
.PHONY:build

Each possible operation is called a target. The .DEFAULT_GOAL defines which target is run when no target is specified. In our case, we are going to run the build target.

The world before the colon (:) is the name of the target. Any words after the target (like vet in the line build: vet) are the other targets that must be run before the specified target runs. The taks that are performed by the target are on the indented lines after the target (The)

Once theMakefile is in your directory, type:

1
> make

Chapter.2 - Primative Types and Declarations

Chapter.3 - Composite Types

Chapter.4 - Blocks, Shadows, and Control Structures

Chapter.5 - Functions

Chapter.6 - Pointers

Chapter.7 - Types, Methods, and Interfaces

Chapter.8 - Errors