GoLang Tutorial - HelloWorld
Go (often referred to as Golang) is a programming language created by Google in 2009. Go is a statically typed, compiled language in the tradition of C, with memory safety, garbage collection, structural typing, and CSP-style concurrency. - Go (Golang)
Download an appropriate package from The Go Programming Language - Downloads.
For me, it's macOS package.
The package installs the Go distribution to /usr/local/go.
The package should put the /usr/local/go/bin directory in our PATH environment variable:
$PATH /usr/local/go/bin
We may need to restart any open Terminal sessions for the change to take effect.
Ref: Test your installation.
Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.
Create workspace directory, $HOME/go:
$ mkdir -p $HOME/go
If we to use a different directory, we will need to set the GOPATH environment variable.
Next, make the directory src/hello inside the workspace:
$ mkdir -p src/hello
Then, in that directory create a file named hello.go that looks like:
package main import "fmt" func main() { fmt.Printf("hello, world\n") }
Then build it with the go tool:
$ cd $HOME/go/src/hello $ go build
The command above will build an executable named hello in the directory alongside our source code. Execute it to see the greeting:
$ ./hello hello, world
If we see the "hello, world" message then our Go installation is working.
We can run go install to install the binary into our workspace's bin directory or go clean -i to remove it.
Go Tutorial
- GoLang Tutorial - HelloWorld
- Calling code in an external package & go.mod / go.sum files
- Workspaces
- Workspaces II
- Visual Studio Code
- Data Types and Variables
- byte and rune
- Packages
- Functions
- Arrays and Slices
- A function taking and returning a slice
- Conditionals
- Loops
- Maps
- Range
- Pointers
- Closures and Anonymous Functions
- Structs and receiver methods
- Value or Pointer Receivers
- Interfaces
- Web Application Part 0 (Introduction)
- Web Application Part 1 (Basic)
- Web Application Part 2 (Using net/http)
- Web Application Part 3 (Adding "edit" capability)
- Web Application Part 4 (Handling non-existent pages and saving pages)
- Web Application Part 5 (Error handling and template caching)
- Web Application Part 6 (Validating the title with a regular expression)
- Web Application Part 7 (Function Literals and Closures)
- Building Docker image and deploying Go application to a Kubernetes cluster (minikube)
- Serverless Framework (Serverless Application Model-SAM)
- Serverless Web API with AWS Lambda
- Arrays vs Slices with an array left rotation sample
- Variadic Functions
- Goroutines
- Channels ("<-")
- Channels ("<-") with Select
- Channels ("<-") with worker pools
- Defer
- GoLang Panic and Recover
- String Formatting
- JSON
- SQLite
- Modules 0: Using External Go Modules from GitHub
- Modules 1 (Creating a new module)
- Modules 2 (Adding Dependencies)
- AWS SDK for Go (S3 listing)
- Linked List
- Binary Search Tree (BST) Part 1 (Tree/Node structs with insert and print functions)
- Go Application Authentication I (BasicAuth, Bearer-Token-Based Authentication)
- Go Application Authentication II (JWT Authentication)
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization