Jordan Taylor
justjordant

justjordant

Day 1 - Get Going With GO.

Day 1 - Get Going With GO.

Jordan Taylor's photo
Jordan Taylor
·May 24, 2022·

3 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Table of contents

  • Day 1 - Get Going With GO!

Day 1 - Get Going With GO!

Before we start, I would like to go over some prerequisites that we should know before learning GO.

Prerequisites

  • Some programming experience. The code here is pretty simple, but it helps to know something about functions.
  • APIs. On some days we will be working on making our own APIs, so this would be good to have some experience with using them.
  • A tool to edit your code. Any text editor you have will work fine. Most text editors have good support for Go. The most popular are VSCode (free), GoLand (paid) - (Free for students), and Vim (free).
  • A command terminal. Go works well using any terminal on Linux and Mac, and on PowerShell or cmd on Windows.

What Is GO?

Go is a programming language that was made by Google in 2007 to improve Programming productivity The creators of Go wanted to address criticism of other languages in use at Google, but keep their useful characteristics.

How can GO help us?

Build fast, reliable, and efficient software at scale this is what we can achieve with using GO.

Minimalist

If you’ve played with the basics of Go, you will notice that the language is not trying to be overly complex or impressive. It’s just enough to get the job done.

Example HTTP server.

package main

import (
    "fmt"
    "net/http"
)

func hello(w http.ResponseWriter, req *http.Request) {

    fmt.Fprintf(w, "hello\n")
}

func headers(w http.ResponseWriter, req *http.Request) {

    for name, headers := range req.Header {
        for _, h := range headers {
            fmt.Fprintf(w, "%v: %v\n", name, h)
        }
    }
}

func main() {

    http.HandleFunc("/hello", hello)
    http.HandleFunc("/headers", headers)

    http.ListenAndServe(":8080", nil)
}

Output:

$ go run http-servers.go 

$ curl localhost:8080/hello
hello

Formating

There is one built-in formatting engine, no need to use things like prettier.js and there’s no need to re-invent the wheel. Gofmt is a tool that automatically formats Go source code.

Low boilerplate code

Go requires very little boilerplate code to create substantial applications, unlike Rust which requires far more boilerplate code when matching equivalent capabilities. By now you have seen that you can write meaningful code with fewer lines using GO compared to other languages.

Example Hello World in GO.

package main

import "fmt"

func main() {
    fmt.Println("hello world")
}

Why should we be using GO?

Even though Go is different from other object-oriented languages, it is still the same. Go provides you high performance like C/C++, super-efficient concurrency handling like Java and fun to code like Python/Perl.

Resources

Did you find this article valuable?

Support Jordan Taylor by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this