Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 147 ยท Getting Started

Getting Started with Go

Learn what Go is, why Google created it, where it is used, and run your first Go program in the browser. A friendly start to the Go (Golang) programming language.

Go (often called Golang, because of its old website address) is a compiled, statically typed programming language that was built to make everyday software engineering less painful. It reads almost like a scripting language, yet it compiles to a fast, self-contained program, and it has concurrency, the ability to do many things at once, built into the language itself.

This course takes you from "what is a variable?" to goroutines, generics, testing, web servers and complete projects. You don't have to install anything to begin: every example marked Try it compiles and runs on our server, and you can edit it and press Run as often as you like. This first lesson explains what Go is for, then runs your first program.

Where Go came from

Go was designed at Google starting in 2007 by Robert Griesemer, Rob Pike and Ken Thompson (who had earlier worked on Unix and the C language). It was announced publicly in 2009, and Go 1.0 shipped in March 2012 with a promise that is still the heart of the language: programs written for Go 1 keep compiling with later Go 1.x releases. That is called the Go 1 compatibility promise, and it is one reason Go code stays useful for years.

The designers were frustrated by slow builds, tangled dependencies and the complexity of large C++ and Java code bases. Their answer was a language with a deliberately small feature set:

  • Simplicity. The language specification is short enough to read in an afternoon. There are no classes, no inheritance, no exceptions and no operator overloading. There is usually one obvious way to write something.
  • Fast builds. Even a large project compiles in seconds. The compiler is fast, and the language is designed so dependencies are cheap to analyze.
  • Built-in concurrency. Lightweight threads called goroutines and typed pipes called channels make concurrent programs short and readable. You will meet them in Goroutines.
  • One standard formatting. The gofmt tool formats every Go file the same way, so there are no arguments about style.
  • A strong standard library. Web servers, JSON, cryptography, testing and much more ship with the language, so many programs need no third-party code at all.

You will see both "Go" and "Golang". The language's name is Go. "Golang" survives in the domain name golang.org and is handy when you search the web, because "go" alone is a very common word.

What people build with Go

Go is popular wherever programs must be fast to start, easy to deploy and good at handling many connections:

  • Cloud and infrastructure tools. Docker, Kubernetes, Terraform, Prometheus and Caddy are all written in Go.
  • Web services and APIs. The standard net/http package is production quality, and companies run huge back ends in Go.
  • Command-line tools. A Go program compiles to a single file with no runtime to install. That makes it a favorite for tools such as the GitHub CLI and Hugo.
  • Networking, data pipelines and DevOps automation.

Well-known systems built with Go include Docker and Kubernetes (with Red Hat's OpenShift on top of it), the InfluxDB time-series database, and many services at companies such as Dropbox, Uber and Netflix. Go's goroutines and static binaries are why it became the default language of cloud-native tooling.

Go is less common for desktop GUIs, games and data-science notebooks, where other ecosystems are stronger. That is fine: Go is a tool, not a religion.

Your first Go program

Here is the traditional first program. Press Run and look at the output below the editor.

Go Hello, Go

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with bufio.Scanner or fmt.Scan), it gets the next line from this box.

Every line has a job:

  1. package main says this file belongs to the main package. A package named main is special: it builds into a program you can run, instead of a library for other code.
  2. import "fmt" makes the standard fmt package (short for "format") available. It handles printing and text formatting.
  3. func main() { ... } declares the function named main. Go starts your program by calling it.
  4. fmt.Println("Hello, Go!") calls the Println function from fmt. It prints its arguments followed by a newline.

Notice what is missing: no semicolons at the end of lines, no parentheses around anything extra, and no class wrapping the code. The next few lessons explain these rules, in How Go Works and Go Syntax.

Change it and run it again

The best way to learn is to break things. Try this version, which prints several values and does a little math:

Go Printing text and numbers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with bufio.Scanner or fmt.Scan), it gets the next line from this box.

Some things to notice in the output:

  • Println puts a space between its arguments.
  • 10 / 4 prints 2, not 2.5. Both numbers are integers, so Go does integer division. Using 4.0 makes the division floating point.
  • The character 'A' in single quotes is a rune (a Unicode code point), and printing it shows its number, 65. Strings use double quotes. Strings, Bytes and Runes explains the difference.

Variables, loops and functions in one glance

You do not need to understand every detail yet. This program gives you a taste of what the next lessons teach in depth. It defines a function, declares variables, and loops:

Go A taste of Go

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with bufio.Scanner or fmt.Scan), it gets the next line from this box.

A few quick explanations:

  • func square(n int) int takes one int and returns an int. In Go the type comes after the name.
  • total := 0 declares a new variable and lets Go work out that it is an int. The := form only works inside functions.
  • for is Go's only loop keyword. It covers counting loops, while-style loops and loops over collections.
  • []string{...} is a slice, a growable list of strings. range walks through it and hands you the index and the value.

Go is statically typed, but it feels light

Go checks types when it compiles, so many mistakes never reach a user. At the same time you rarely have to write types out, because := infers them. Here is what a type error looks like. This example fails on purpose:

Go A type mistake (fails on purpose)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with bufio.Scanner or fmt.Scan), it gets the next line from this box.

The compiler refuses to build the program and prints:

TEXT
./main.go:7:8: cannot use "thirty" (untyped string constant) as int value in assignment

The message gives the file, the line number (7), the column (8) and a plain-language reason. age became an int the moment it was created, and a string cannot be stored in it. Go compilers are strict, but their messages are usually clear. Go Syntax shows how to read them.

How Go is released

Go follows a steady rhythm: a new version arrives every six months, in February and August. This course teaches Go 1.27, and the examples compile with it. Each release is supported until two newer major versions exist, so you always have a way to stay current.

Because of the compatibility promise, a new release almost never breaks working code. New features arrive carefully. For example, generics came in Go 1.18, for loops over integers and the slices and maps packages arrived in Go 1.21 to 1.22, and iterators followed in Go 1.23. Whenever this course teaches a feature that is newer than Go 1.20, it names the version, so you can tell whether the code will work on an older toolchain.

When you read Go code on the internet, check its date. Older articles often use patterns that modern Go replaces with something simpler, such as sort.Slice (now often slices.SortFunc) or interface{} (now any). This course always teaches the current idioms and mentions the old form only so you can recognize it.

How to use this course

  • Read each lesson, then run and modify the examples. Type changes by hand rather than copying.
  • Lessons are grouped into chapters that build on each other. The sidebar tracks which lessons you have completed when you are signed in.
  • Every lesson ends with a short quiz. If you miss a question, read its explanation, because that is where the common traps are explained.
  • Projects near the end combine everything into real programs.

When you want to run Go on your own computer, How Go Works shows how the go command compiles and runs programs, and The go Command and Basic Tooling covers the everyday tools.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does a Go file need so that it builds into a runnable program?

    A runnable Go program lives in package main and starts at func main(). fmt is only needed if you print, and Go has no classes.
  2. 2. What does fmt.Println(10 / 4) print?

    Both operands are untyped integer constants, so Go does integer division and drops the fraction.
  3. 3. Which of these is NOT a goal Go was designed around?

    Go has no classes and no inheritance. It reuses code through composition and interfaces instead.
  4. 4. In 'total := 0', what does := do?

    The short variable declaration := creates a new variable and infers its type from the value (int here). It only works inside functions.
  5. 5. How often does a new Go version come out?

    Go ships a major release in February and August every year, which makes upgrades predictable.

Summary

  • Go is a compiled, statically typed language created at Google, with a small feature set, fast builds and built-in concurrency.
  • It is widely used for cloud tools, web services and command-line programs.
  • A runnable program is in package main and starts at func main().
  • fmt.Println prints values separated by spaces and ends with a newline.
  • Types are checked at compile time, and the compiler's error messages tell you the line and column.
  • New Go versions arrive every six months, and the Go 1 compatibility promise keeps old code working.

Next: How Go Works: Compiling and Running shows what happens between your source file and a running program.