December 2017
Intermediate to advanced
316 pages
6h 58m
English
Go's net/http package deals with HTTP client and server implementations. Here, we are mainly interested in the server implementation. Let us create a small Go program called basicHandler.go that defines the route and a function handler:
package mainimport ( "io" "net/http" "log")// hello world, the web serverfunc MyServer(w http.ResponseWriter, req *http.Request) { io.WriteString(w, "hello, world!\n")}func main() { http.HandleFunc("/hello", MyServer) log.Fatal(http.ListenAndServe(":8000", nil))}This code does the following things:
Read now
Unlock full access