February 2018
Intermediate to advanced
246 pages
6h 3m
English
Go provides us with an inbuilt library for building web servers, net/http. For every endpoint we want to create on our server, we have to do two things:
The following is a simple web server that accepts all incoming requests, logs them on to the console, and then returns a Hello, World! message.
// helloServer.go package main import ( "fmt" "log" "net/http" ) func helloWorldHandler(w http.ResponseWriter, r *http.Request) { msg := fmt.Sprintf("Received request [%s] for path: [%s]", r.Method, r.URL.Path) log.Println(msg) response := ...Read now
Unlock full access