Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

learn-go

> 编程语言
Open source

Master the fundamentals and advanced features of the Go programming language

1.3K stars0 likes0 views
WebsiteGitHub

About

Master the fundamentals and advanced features of the Go programming language

Learn Go

Hey, welcome to the course, and thanks for learning Go. I hope this course provides a great learning experience.

This course is also available on my website and as an ebook on leanpub. Please leave a ⭐ as motivation if this was helpful!

Table of contents

  • Getting Started

    • What is Go?
    • Why learn Go?
    • Installation and Setup
  • Chapter I

    • Hello World
    • Variables and Data Types
    • String Formatting
    • Flow Control
    • Functions
    • Modules
    • Packages
    • Workspaces
    • Useful Commands
    • Build
  • Chapter II

    • Pointers
    • Structs
    • Methods
    • Arrays and Slices
    • Maps
  • Chapter III

    • Interfaces
    • Errors
    • Panic and Recover
    • Testing
    • Generics
  • Chapter IV

    • Concurrency
    • Goroutines
    • Channels
    • Select
    • Sync Package
    • Advanced Concurrency Patterns
    • Context
  • Appendix

    • Next Steps
    • References

What is Go?

Go (also known as Golang) is a programming language developed at Google in 2007 and open-sourced in 2009.

It focuses on simplicity, reliability, and efficiency. It was designed to combine the efficacy, speed, and safety of a statically typed and compiled language with the ease of programming of a dynamic language to make programming more fun again.

In a way, they wanted to combine the best parts of Python and C++ so that they can build reliable systems that can take advantage of multi-core processors.

Why learn Go?

Before we start this course, let us talk about why we should learn Go.

1. Easy to learn

Go is quite easy to learn and has a supportive and active community.

And being a multipurpose language you can use it for things like backend development, cloud computing, and more recently, data science.

2. Fast and Reliable

Which makes it highly suitable for distributed systems. Projects such as Kubernetes and Docker are written in Go.

3. Simple yet powerful

Go has just 25 keywords which makes it easy to read, write and maintain. The language itself is concise.

But don't be fooled by the simplicity, Go has several powerful features that we will later learn in the course.

4. Career opportunities

Go is growing fast and is being adopted by companies of any size. and with that, comes new high-paying job opportunities.

I hope this made you excited about Go. Let's start this course.

Installation and Setup

In this tutorial, we will install Go and setup our code editor.

Download

We can install Go from the downloads section.

Installation

These instructions are from the official website.

MacOS

  1. Open the package file you downloaded and follow the prompts to install Go. The package installs the Go distribution to /usr/local/go. The package should put the /usr/local/go/bin directory in your PATH environment variable. You may need to restart any open Terminal sessions for the change to take effect.

  2. Verify that you've installed Go by opening a command prompt and typing the following command:

$ go version
  1. Confirm that the command prints the installed version of Go.

Linux

  1. Remove any previous Go installation by deleting the /usr/local/go folder (if it exists), then extract the archive you just downloaded into /usr/local, creating a fresh Go tree in /usr/local/go:
$ rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.1.linux-amd64.tar.gz

Note: You may need to run the command as root or through sudo.

Do not untar the archive into an existing /usr/local/go tree. This is known to produce broken Go installations.

  1. Add /usr/local/go/bin to the PATH environment variable. You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):
bash
export PATH=$PATH:/usr/local/go/bin

Note: Changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as source $HOME/.profile.

  1. Verify that you've installed Go by opening a command prompt and typing the following command:
$ go version
  1. Confirm that the command prints the installed version of Go.

Windows

  1. Open the MSI file you downloaded and follow the prompts to install Go.

By default, the installer will install Go to Program Files or Program Files (x86). You can change the location as needed. After installing, you will need to close and reopen any open command prompts so that changes to the environment made by the installer are reflected at the command prompt.

  1. Verify that you've installed Go.
    1. In Windows, click the Start menu.
    2. In the menu's search box, type cmd, then press the Enter key.
    3. In the Command Prompt window that appears, type the following command:
$ go version
  1. Confirm that the command prints the installed version of Go.

VS Code

In this course, I will be using VS Code and you can download it from here.

Feel free to use any other code editor you prefer.

Extension

Make sure to also install the Go extension which makes it easier to work with Go in VS Code.

This is it for the installation and setup of Go, let's start the course and write our first hello world!

Hello World

Let's write our first hello world program, we can start by initializing a module. For that, we can use the go mod command.

bash
$ go mod init example

But wait...what's a module? Don't worry we will discuss that soon! But for now, assume that the module is basically a collection of Go packages.

Moving ahead, let's now create a main.go file and write a program that simply prints hello world.

go
package main

import "fmt"

func main() {
	fmt.Println("Hello World!")
}

If you're wondering, fmt is part of the Go standard library which is a set of core packages provided by the language.

Structure of a Go program

Now, let's quickly break down what we did here, or rather the structure of a Go program.

First, we defined a package such as main.

go
package main

Then, we have some imports.

go
import "fmt"

Last but not least, is our main function which acts as an entry point for our application, just like in other languages like C, Java, or C#.

go
func main() {
	...
}

Remember, the goal here is to keep a mental note, and later in the course, we'll learn about functions, imports, and other things in detail!

Finally, to run our code, we can simply use go run command.

bash
$ go run main.go
Hello World!

Congratulations, you just wrote your first Go program!

Variables and Data Types

In this tutorial, we will learn about variables. We will also learn about the different data types that Go provides us.

Variables

Let's start with declaring a variable.

This is also known as declaration without initialization:

go
var foo string

Declaration with initialization:

go
var foo string = "Go is awesome"

Multiple declarations:

go
var foo, bar string = "Hello", "World"
// OR
var (
	foo string = "Hello"
	bar string  = "World"
)

Type is omitted but will be inferred:

go
var foo = "What's my type?"

Shorthand declaration, here we omit var keyword and type is always implicit. This is how we will see variables being declared most of the time. We also use the := for declaration plus assignment.

go
foo := "Shorthand!"

Note: Shorthand only works inside function bodies.

Constants

We can also declare constants with the const keyword. Which as the name suggests, are fixed values that cannot be reassigned.

go
const constant = "This is a constant"

It is also important to note that, only constants can be assigned to other constants.

go
const a = 10
const b = a // ✅ Works

var a = 10
const b = a // ❌ a (variable of type int) is not constant (InvalidConstInit)

Data Types

Perfect! Now let's look at some basic data types available in Go. Starting with string.

String

In Go, a string is a sequence of bytes. They are declared either using double quotes or backticks which can span multiple lines.

go
var name string = "My name is Go"

var bio string = `I am statically typed.
									I was designed at Google.`

Bool

Next is bool which is used to store boolean values. It can have two possible values - true or false.

go
var value bool = false
var isItTrue bool = true

Operators

We can use the following operators on boolean types

Type Syntax
Logical && || !
Equality == !=

Numeric types

Now, let's talk about numeric types.

Signed and Unsigned integers

Go has several built-in integer types of varying sizes for storing signed and unsigned integers

The size of the generic int and uint types are platform-dependent. This means it is 32-bits wide on a 32-bit system and 64-bits wide on a 64-bit system.

go
var i int = 404                     // Platform dependent
var i8 int8 = 127                   // -128 to 127
var i16 int16 = 32767               // -2^15 to 2^15 - 1
var i32 int32 = -2147483647         // -2^31 to 2^31 - 1
var i64 int64 = 9223372036854775807 // -2^63 to 2^63 - 1

Similar to signed integers, we have unsigned integers.

go
var ui uint = 404                     // Platform dependent
var ui8 uint8 = 255                   // 0 to 255
var ui16 uint16 = 65535               // 0 to 2^16-1
var ui32 uint32 = 2147483647          // 0 to 2^32-1
var ui64 uint64 = 9223372036854775807 // 0 to 2^64-1
var uiptr uintptr                     // Integer representation of a memory address

If you noticed, there's also an unsigned integer pointer uintptr type, which is an integer representation of a memory address. It is not recommended to use this, so we don't have to worry about it.

So which one should we use?

It is recommended that whenever we need an integer value, we should just use int unless we have a specific reason to use a sized or unsigned integer type.

Byte and Rune

Golang has two additional integer types called byte and rune that are aliases for uint8 and int32 data types respectively.

go
type byte = uint8
type rune = int32

A rune represents a unicode code point.

go
var b byte = 'a'
var r rune = ''

Floating point

Next, we have floating point types which are used to store numbers with a decimal component.

Go has two floating point types float32 and float64. Both type follows the IEEE-754 standard.

The default type for floating point values is float64.

go
var f32 float32 = 1.7812 // IEEE-754 32-bit
var f64 float64 = 3.1415 // IEEE-754 64-bit

Operators

Go provides several operators for performing operations on numeric types.

Type Syntax
Arithmetic + - * / %
Comparison == != `` =
Bitwise & | ^ `>

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Gocoursegogolangtech

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言