Your First Program in Go Programming Language Tutorial Online
Go (a.k.a GoLang) is an open-source programming language that makes it easy to build simple, reliable, and efficient software. Go is gaining popularity, because of easy to use, concurrency mechanisms that get the most out of multicore and networked machines, Garbage collection, modular and flexible program structure, and more.
If you have worked in C++ you will able to understand the syntax of Go. Some new ways to use for loop and did I mentioned that you can return 2 variables from a function instead of 1. It also uses pointers.
As I have worked with GoLang and made APIs, it was quite easy and code was concise. If you want me to make videos more Go Programming Language Tutorial, comment below.
Install Go on your system
- Download SDK from this link acc. to your OS.
- Set your environment variable up to
<path>/Go/bin/
, this path will be called as GOROOT - Now the next steps are important, you need to create 1 more environment variables GOPATH
- Create a new folder in your desired location lets say,
~/Go
, this path you will set as GOPATH, in this GOPATH you will make another folder with a namesrc
, - Again make a folder in this
src
with a domain name as I have madenavoki.com
as a folder name, this folder will contain all your projects. Now within this Go folder, you will install all dependencies, Go will make folder here. These steps are necessary. - You are ready to work with GO
- Now create
main.go
file innavoki.com
write this code
package main import "fmt" func main() { fmt.Println("Hello, World!") }
7. open Command Prompt window here and type
C:\Users\TheDoctor\go\src\goprojects\hello>go run main.go Hello, World!
And the output is printed.
Explanation
package main
is a package declaration, every program should begin with this. Packages are Go’s way of organizing and reusing codeimport "fmt"
, Packagefmt
implements formatted I/O with functions analogous to C’sprintf
andscanf
.main()
is the starting point of your program.fmt.Println("Hello, World!")
, obviously prints the data on the terminal- and you don’t need
;
in go
Now you can experiment with other coding blocks like for loop,if-else, Lists, etc. if you need any tutorial for basic co basic core Go or APIs with GO, let me know in the comments below.