Mastering Go Application Design: HTTP Path Parameters (Part 2)

Part 1 , Part 2 HTTP Api’s often use the url path to identify resource name, id and possibly an action. These parts of the URL path are divided by the / character. Here is an example of using path parameters to implement a key value store where data is saved using the following request GET /set/$key/$value and retrieved using the request GET /get/$key using only the standard library. Go Playground: https://go....

Mastering Go Application Design: HTTP Servers (Part 1)

Part 1 , Part 2 Go is an excellent choice for writing your next http service. It supports multithreaded request handling with the standard library and many other convenient features that makes creating a new application a breeze. Here is an example of a http service that returns the current time as json. Playground: https://go.dev/play/p/gZGKLEhHkPR package main import ( "encoding/json" "log" "net/http" "time" ) // Response is a simple json response // that will be returned by the http server // the json tags are used to specify the // json keys type Response struct { Status string `json:"status"` // json key is "status" Time string `json:"time"` // json key is "time" } // this is a simple http server that returns a json response func main() { // create a new http serve mux // the serve mux is used to register http handlers // for different paths mux := http....

Mastering Concurrency in Go: With Fanout and Goroutines (Part 1)

Part 1 , Part 2 , Part 3 , Part 4 , Part 5 Goroutines can be used to take advantage of CPUs with multiple processors. Starting a Goroutine using the “go” keyword, will start execution on a thread in parallel if a thread is available. You will need to make sure that your main function does not exit before all the goroutines finish their work. Playground: https://go.dev/play/p/FTJLzwY34l2 package main import ( "fmt" "sync" ) func main() { wg := sync....