There are thousands of programming languages in the world and there are hundreds of public and known programming languages. From those languages only few are very popular due to several factors such as speed, ease of programming and portability.

Why Google created Go (Google’s golang)?

Efficient compilation, efficient execution and ease of programming were not appeared in a same mainstream language all together. That is why Google started a new programming language called golang to solve above problem. For an instance developers can choose Python when ease of programming is important. But as we know python is very slow since it is an interpreted language. Thus developers will select C or C++ when performance is a major factor. But as we know coding with C or C++ is not easy since it is closer to hardware not to the human.

Golang is designed by Google’s superminds to be fast, fun for humans and in other hand also to be fast, efficient for computers.

Golang features and characteristics

  • It is a statically typed, fast compiled language designed for modern development.
  • Produces binary executable, like C++
  • Powerful at Concurrency to allow systems to be built to scale and effectively use the computing power available.
  • Empowered by the open source community.
  • Automatic type inference (similar to dynamic languages)
  • Strict compilation checking, unused packages and variables will prevent compilation.
  • Powerful standard library
  • Awesome at building API’s or backends
  • Cross platform (Runs on Linux/ Mac/ Windows. Currently has experimental mobile support ).
  • Useful tools for code linting, code generation, building, testing, etc.

Getting started with golang

Golang is easy to install and also easy to get started with coding. Therefore why don’t you go ahead and try!

Download and install

Hello World in golang

Enter following code in your favorite text editor and save as “hello.go”

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

“fmt” contains I/O functions and it is similar to “stdio.h” in C language.

Compile the code into binary format using following command

$ go build hello.go

Execute the binary file using hello in Windows or ./hello in Linux

Simple HTTP Server in golang

golang can be used to write back-ends or APIs. Following example shows how easy to create a http server with golang.

package main
 
 import "net/http"
 
 func sayHello(w http.ResponseWriter, r *http.Request) {
   message := "Hello World from API"
   w.Write([]byte(message))
 }
 
 func main() {
   http.HandleFunc("/", sayHello)
   if err := http.ListenAndServe(":8080", nil); err != nil {
     panic(err)
   }
 }

Check “localhost:8080” from your web browser.

Thanks for reading. We’ll meet with next golang article. Happy Coding with golang