Book Image

Hands-On Full Stack Development with Go

By : Mina Andrawos
Book Image

Hands-On Full Stack Development with Go

By: Mina Andrawos

Overview of this book

The Go programming language has been rapidly adopted by developers for building web applications. With its impressive performance and ease of development, Go enjoys the support of a wide variety of open source frameworks, for building scalable and high-performant web services and apps. Hands-On Full Stack Development with Go is a comprehensive guide that covers all aspects of full stack development with Go. This clearly written, example-rich book begins with a practical exposure to Go development and moves on to build a frontend with the popular React framework. From there, you will build RESTful web APIs utilizing the Gin framework. After that, we will dive deeper into important software backend concepts, such as connecting to the database via an ORM, designing routes for your services, securing your services, and even charging credit cards via the popular Stripe API. We will also cover how to test, and benchmark your applications efficiently in a production environment. In the concluding chapters, we will cover isomorphic developments in pure Go by learning about GopherJS. As you progress through the book, you'll gradually build a musical instrument online store application from scratch. By the end of the book, you will be confident in taking on full stack web applications in Go.
Table of Contents (15 chapters)
Free Chapter
1
Section 1: The Go Language
5
Section 2: The Frontend
8
Section 3: Web APIs and Middleware in Go

Goroutines

It's now time to dig deeper into the clean API that Go provides in order to write concurrent software with ease.

A goroutine is simply defined as a light-weight thread that you can use in your program; it's not a real thread. In Go, when you define a piece of code as a new goroutine, you basically tell the Go runtime that you would like this piece of code to run concurrently with other goroutines.

Every function in Go lives in some goroutine. For example, the main function that we discussed in the previous chapter, which is usually the entry point function for your program, runs on what is known as the main goroutine.

So, how do you create a new goroutine? You just append the go keyword before the function that you would like to run concurrently. The syntax is quite simple:

go somefunction()

Here, somefunction() is the piece of code that you would like to...