Whatbox Logo

Wiki > Go

Introduction

Go or Golang is an open source programming language created at Google. It is a compiled, statically typed language in the style of Algol and C, with garbage collection, limited structural typing, memory safety features and CSP-style concurrent programming features.

This guide will cover how to use Go, as well as how to test it with a small and simple "Hello world!" program.

Usage

To run a file with Go, simply do the following:

go run <name of file to run>

Alternatively you can 'compile' the Go program with go build <name of file to build> which will create a binary of the file.

Simple Hello World Test

To verify that Go is working, the following is an easy and simple test that will print Hello world! to the terminal.

  1. Create the file for this test

     touch helloworld.go
    
  2. Copy the contents of the box below into the helloworld.go file

helloworld.go

package main

import "fmt"

func main() {
    fmt.Println("Hello world!")
}
  1. Run the Go program with the following command

     go run helloworld.go
    

If everything is working, you should see Hello world! in the terminal! You can also build the program with go build helloworld.go, which means that you won't have to wait for Go to recompile the program every time you want to run it.

Further Learning

Go documentation can be found on their official website at go.dev/doc.