Monday, May 14, 2018

A Tour Of Go

Hi All,

Today I'm going to introduce a nice tool which you can use to learn Golang, it's called "A Tour Of Go". This tool is available in both online and offline. Following is the link for the online version.



Let see how to use offline version,

After you install Golang on your PC, you can run the following command to open "A Tour Of Go"

go tool tour



Saturday, May 12, 2018

Test your Golang installation is up & running

Hi All,

Today we are going to make simple "Hello World" program to make sure our Golang installation is up and running.

Open your terminal and go to hello folder we make in the last lesson, for me it's,

cd /workspace/go/src/github.com/nisalsp9/hello

After you went there open your text editor I'm going to use gedit, following is the command,

gedit

Now your gedit will open copy and paste following code, 


package main

import "fmt"

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

}

Note:  Don't worry about all those syntaxes I will teach you about them in upcoming posts,

Now save your code using hello.go as the file name.

Okay, let's compile ( build ) your code by using the following command,

go build


  Now let's run the hello world program, following is the command,

./hello



See you guys in my next post, bye !!!!!!

Monday, March 26, 2018

How To Install Golang

Hi All,

In this post, I will teach you how to install Golang on your PC, currently, I'm working on Ubuntu OS  I will show you how to install Golang on Ubuntu OS first.

Go to the following link,

https://golang.org/dl/

Then download Golang according to your OS I'm on Ubuntu so I'm going to download Linux one from here,



After your download is finished you have to go to where your download file is placed and then extract it into /usr/local creating Go tree /usr/local/go. Use the following command as sudo.  

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


Now we have to set /usr/local/go/bin to the PATH environment variable. Use the following command to open bashrc via Vim text editor or use any text editor. 

sudo vim ~/.bashrc

Then add the following line to bottom of the file,

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


Let's create a workplace for Go and test our installation is working or not by using a sample code.

Go to your home by using the following command,

cd /home/username/

Then create directory call workplace using the following command,  

mkdir workplace

Then go inside that created directory and create directory call go,

mkdir go

Then go inside that created directory and create directory call src,

mkdir src

We will use GitHub for later in our projects so let's create github.com directory inside the src directory,

mkdir github.com

Then inside the github.com directory make a directory with your Github username.

mkdir yourusername


Following is my workspace path,

workspace/go/src/github.com/nisalsp9/


Let's create our first project directory, go inside your GitHub username directory and make the following directory,

mkdir hello    


Before we start our test project we have to set GOPATH to our workspace, open bashrc add following lines to the bottom of the file.

export GOPATH="/home/nisalsp9/workspace/go"
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
export GOROOT=/usr/local/go

After you add above line you have to source the bashrc file use following command to do that,

source ~/.bashrc 


We will create a hello world program in our next post and test our installation is working, bye ..!

Following are references to Golang installation in different OSs,





How To Write Go Code

Hi All,

At first place, I would like to apologize not to write a post for ages, From today onwards I will post once or twice a week.

In this blog Go What? Why? How? I have written simple posts about What is Golang and Why we use Golang. From today onwards I will write posts about How to write Go Codes.

For ease of both teaching and learning, I will  upcoming posts mainly into three parts,

  1. Programming Fundamentals. 
  2. Advanced Programming. 
  3. Create Golang based web project with MySQL database.

See you guys in my next post. bye....!