golang

[golang] Writing a simple application in golang

What is GO(golang)?

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. Go, also commonly referred to as golang, is a programming language developed at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It is a statically-typed language with syntax loosely derived from that of C, adding garbage collection, type safety, some dynamic-typing capabilities, additional built-in types such as variable-length arrays and key-value maps, and a large standard library.

Writing a Simple Application from GO

Before writing anything there are some things we need to cover. code structure, installing, building and running are some of these. We will go through the motions with this tutorial.

Setting up Environment

Setting up the environment for GO is important and is essential. Let’s first download and setup GO in the local machine. You can download GO from here. I’m using a linux machine so instructions may be specific to a linux environment. Installation guide if required is available here.

1. After downloading extract the distribution (I downloaded version 1.4.2) to “/usr/local”

tar -C /usr/local -xzf go1.4.2.linux-amd64.tar.gz

2. Add the path to GO/bin as an environment variable (can be to $HOME/.bash_profile, $HOME/.bashrc or $HOME/.profile).

export PATH=$PATH:/usr/local/go/bin

Now test if GO is successfully installed.

$go version
go version go1.4.2 linux/amd64

Writing an running the first GO application

Create a file named hello.go and write the following program;

package main

import "fmt"

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

Then run it with the go tool which is packed with the GO installation:

$ go run hello.go
Hello World!!!

Thats Go for you. A simple Hello World application.

One Reply to “[golang] Writing a simple application in golang”

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.