Book Image

Security with Go

By : John Daniel Leon, Karthik Gaekwad
Book Image

Security with Go

By: John Daniel Leon, Karthik Gaekwad

Overview of this book

Go is becoming more and more popular as a language for security experts. Its wide use in server and cloud environments, its speed and ease of use, and its evident capabilities for data analysis, have made it a prime choice for developers who need to think about security. Security with Go is the first Golang security book, and it is useful for both blue team and red team applications. With this book, you will learn how to write secure software, monitor your systems, secure your data, attack systems, and extract information. Defensive topics include cryptography, forensics, packet capturing, and building secure web applications. Offensive topics include brute force, port scanning, packet injection, web scraping, social engineering, and post exploitation techniques.
Table of Contents (15 chapters)

Goroutines

Goroutines are lightweight threads built into the language. You simply have to put the word go in front of a function call to have the function execute in a thread. Goroutines may also be referred to as threads in this book.

Go does provide mutexes, but they are avoidable in most cases and will not be covered in this book. You can read more about mutexes in the sync package documentation at https://golang.org/pkg/sync/. Channels should be used instead for sharing data and communicating between threads. Channels were covered earlier in this chapter.

Note that the log package is safe to use concurrently, but the fmt package is not. Here is a short example of using goroutines:

package main

import (
"log"
"time"
)

func countDown() {
for i := 5; i >= 0; i-- {
log.Println(i)
time.Sleep(time.Millisecond * 500)
}
}

func main() {
// Kick...