Chapters
Table Of Contents
Install Go toolchain
Windows setup
Mac OS setup
Linux setup
Hello, World!
Take a guided tour
Access documentation offline
Run Go in online playground
GOPATH, GOROOT, GOBIN
Release history
Booleans
Integers
Floating-point numbers
Characters and runes
Strings
Constants
Enums
Arrays
Slices
Maps
Structures
Interfaces
Empty interface
Pointers
Unions
Channels
Zero values
Type aliases
Type casting
Basic variable declaration
Multiple variable assignment
Blank identifier
Typed vs. untyped constants
iota
Emulating enums
Find string in another string
Compare strings
Convert string to lower case or upper case
Remove white space, characters, substrings
Split and join strings
Format text
Parse text
Replace strings
Read text file line by line
Normalize newlines
Basic pointers
Dereferencing pointers
Pointer vs. value methods
Create array
Array indexes
Multidimensional array
Create a slice
Length and capacity
Zero value of slice
Append to slice
Add slices
Filter a slice
Remove elements from slice
Duplicate (create a copy of) a slice
Declare and initialize a map
Create a map
Get value by key
Count number of map entries
Zero value of a map
Copy a map
Iterate over keys, values or both with range
Delete map element
Use map as a set
Maps with slices as values
Concurrent access of maps
Basic declaration
Struct literals
Anonymous structs
Composition and embedding
Exported vs. unexported fields (private vs public)
Tags
Duplicate a struct (make a copy)
Empty struct
Methods
Simple interface
Determining underlying type from interface
Testing Interface Implementation
Type assertion
Type switch
if statement
switch statement
goto statements
Different forms of for loop
break and continue
while loop
Timed loop
range over a string
range over slice
range over a map
range over a channel
Parameters
Variadic functions
Return values
Named return values
Variables of function type
Literal functions
Closures
Creating errors
Create custom error type
Returning an error
Handling an error
Handling errors in short programs
Add callstack to error messages
Good practices for error messages
Defer basics
Defer gotchas
Panic
Recover
Recovering from panic
Panic use cases
Hello World goroutine
Create goroutines
Wait for goroutines to finish
Limiting concurrency with semaphore
Using range to read from a channel
Timout reading from channel with select
Closing channels
Buffered vs. unbuffered channels
Non-blocking receive with select
Signaling channel with chan struct{}
Checking if channel has data available
Read-Write mutes (RWMutex)
Mutex gotchas
Detecting races
Installing packages locally with go get
Importing packages
Creating a package
Package initalization
Package naming best practices
Reading files
Writing files
File operations
Directory operations
Portable file path operations
I/O related interfaces
Format time
Parse time
Format time like strftime
Compare time and date
Raw access to comman line arguments
Libraries for advanced parsing of command-line arguments
Logging libraries
Timing out process execution
os.Exec gotchas
hex
base64
Parsing arbitrary JSON documents
Decoding into anonymous structs
Decoding JSON from a file
Configuring JSON struct fields
Custom JSON marshaling
Go <-> JSON type mappings
XML
Basic decoding / unmarshalling of nested elements with data
CSV
Configuring CSV parsing and writing
SQL
Querying
MySQL
Opening a database
MongoDB: connect & insert & remove & update & query
HTTP POST
PUT request of JSON object
Timeout requests with a context
GET with URL parameters and a JSON response
Set User-Agent
3 ways of doing HTTP requests
Hello World
Create a HTTPS Server
HTTP Hello World with custom server and mux
Responding to an HTTP Request using Templates
Serving content using ServeMux
Using a handler function
Handling http method, accessing query strings & request body
Output values of struct variable to stdout using a text template
Defining functions for calling from template
Single item template
Multiple item template
Templates with custom logic
Templates with structs
HTML templates
How HTML templates prevent malicious code injection
Structs
Slices
reflect.Value.Elem()
Type of value - package "reflect"
Basic reflect.Value Usage
Context with value
Writing cancellable functions
Context is a tree of values
context.TODO() vs. context.Background()
Fmt
Stringer
Basic fmt
Assigning signals to a channel
sync.Pool
Basic Test
Table-driven unit tests
Testing using setUp and tearDown function
Benchmark tests
Example tests (self documenting tests)
Testing HTTP requests
Set/Reset Mock Function In Tests
View code coverage in HTML format
Sending Email with smtp.SendMail()
Cgo: First steps tutorial
Calling C Function From Go
Wire C and Go code in all directions
Basic cpu and memory profiling
Using Benchmarks to Create Profile
Basic memory Profiling
Set CPU/Block profile rate
Accessing Profile File
Build tags
File suffix
Defining separate behaviours in different platforms
Simple cross compilation with go build
Compile all architectures using a Makefile
Cross compilation by using gox
Simple Example: Compile helloworld.go for arm architecture on Linux machine
Separate integration tests
Optimize implementations based on architecture
gob
How to encode data and write to file with gob?
How to read data from file and decode with go?
How to encode an interface with gob?
How to decode an interface with gob?
Structs
Methods
Interface & Polymorphism
Embedded structs
Pointer Vs Value receiver
Use govendor to add external packages
Using trash to manage ./vendor
Use golang/dep
vendor.json using Govendor tool
mgo
Example
Defining and using a plugin
Normal Handler Function
Middleware Calculate time required for handlerFunc to execute
CORS Middleware
Auth Middleware
Recovery Handler to prevent server from crashing
Using Protobuf with Go
Read input from console
Encryption and decryption
Parsing and validating a token using the HMAC signing method
Creating a token using a custom claims type
Creating, signing, and encoding a JWT token using the HMAC signing method
Using the StandardClaims type by itself to parse a token
Parsing the error types using bitfield checks
Getting token from HTTP Authorization header
Basic concepts
Loading and saving image
Cropping image
Convert color image to grayscale
Disabling inline expansion
go fmt
go run
go build
go clean
go get
go env
go test
  ↑ ↓ to navigate     ↵ to select     Esc to close