2 minute read

Introduction

Go’s relatively easier and quicker to learn than few languages like java, C#, C++, etc. As there’re only one way of doing things, creators kept the language decisions simple, and it’s meant for opensource & teams to collaborate easily. We’ll discuss about Technical details later.

One of the reasons to create golang was,

efficient compilation, efficient execution, or ease of programming

all of the three wasn’t available on single mainstream language. read more on Why another language?

Personally, love these

  • go formatting being part of compilation and gofmt, (python took a step but maintaining indentation was an effort)
  • Great package manager (go mod being part of language ecosystem)
  • Channels makes it easy you for you to spin up threads (goroutines)
  • Standard library self sufficient for writing production ready http backend to serve millions of users
  • package standards, dependencies path matching github/vcs repo location
  • performance

Creators

publicly announced in November 2009, and version 1.0 was released in March 2012.

Way to code

Beginner

  • Tour of Go - Covers the basics well for you to write code. You can read, experiment, and code with Go without local setup
  • Godoc getting-started
  • gobyexamples - hands-on introduction to Go using annotated example programs, for instance checkout spinning goroutine

Installation

If you’re on mac prefer brew install go, follow these installation instruction and verify installation with go version

Hello API

why write hello world, when you can write ping API

package main

import (
	"fmt"
	"net/http"
)

func main() {
	fmt.Println("Running API server....")

	// http request multiplexer, or router
	mux := http.NewServeMux()
	mux.HandleFunc("/ping", Ping)
	// running a http server on port 8080
	http.ListenAndServe(":8080", mux)
}

func Ping(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("pong"))
}

You can read more details on go documentation Writing Web Applications

running

  • save this to server.go
  • run go run server.go
  • curl http://localhost:8080/ping and you should see pong in response

Intermediate

  • Go Proverbs The moment you get this, you’re clear on the design principles/philosophy of go and you’ll be able to appreciate interfaces, channels, simplicity and more
  • Effective Go Helps you write standard (idiomatic) go code
  • Ardanlabs Go Blogs
  • Best way to understand a language is to read code and by doing projects, you can start with reading libraries you use
    • negroni
    • gorilla/mux - request router and dispatcher for matching incoming requests to their respective handler

Advanced

Communities

  • gophers slack group. Official channel and you can follow different channels #performance, #jobs etc. Feel free to shoot any questions at #newbies or #general
  • r/golang reddit community
  • meetup groups to network with others in community along with sessions, remote enables you to join meetups worldwide.

Other articles

Note

We’ll share most widely used libraries in production HTTP services, some design philosophies, etc in upcoming posts.