Go lang course

How to Start Programming in Go lang

Golang is a new programming language designed by Google. It is a general purpose, high level programming language that runs on various devices including smartphones.

Easy to read, children can make games with only a little bit of code, a simple challenge for children. Golang is also a fundamental language used for large scale system development. Through working with Golang, children will build confidence in their programming skills.

You can use go by installing it on your home computer (Mac or Windows). Let’s try downloading Go from the official go website. The file is different depending on the type of computer you use, please download the file that corresponds to the type of computer you are using.

https://golang.org/dl/



After the file has finished downloading open it and follow the guide to complete instillation.

After the installation of Go is complete, let’s try making our first program. We will try displaying “hello, world” on the screen.

To start, we will make a directory (folder) for our programming projects. You can make a directory with the Finder (Mac) or Explorer (Windows) but this time we will make it using the terminal.

The terminal is software for executing various commands on the computer. On the Mac press the command+space keys to open Spotlight and type “terminal” to launch the terminal.  In Windows PC内検索で「cmd」と入力して「コマンド プロンプト」を開いてください。

Once the terminal is open, using the command to make a directories, try making a directory called “hello”. Copy the below “mkdir” command into the terminal and press the return key. Do not copy the “$” or “>” as they are just symbols to let the user know the computer is waiting for input.

On Mac
$ mkdir $HOME/go/src/hello

On Windows
> mkdir \go\src\hello

Continuing, move into the new directory. Use the command cd to change directories and move into “hello”. Copy the command below and execute it in the terminal.

On Mac
$ cd $HOME/go/src/hello

On Windows
> cd \go\src\hello

Creating a Go Program

We will create a Go program as a text file. On the Mac using the touch command create an empty file named “hello.go”, the open command will open it. In Windows use the notepad command to start the notepad.

On Mac
$ touch hello.go
$ open -e hello.go

On Windows
> notepad hello.go

Open the text editor, copy and paste the code below, then save the file.

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

Executing a Go Program

After hello.go is saved, return to the terminal and use the “go run” command to execute the program you just made. Copy and execute the command below. If the command displays “hello, world” you successfully executed your first Go program!

$ go run hello.go
BACK