Creating a website in Go

Do you remember the keyValue.go application from Chapter 4, The Uses of Composite Types, and kvSaveLoad.go from Chapter 8, Telling a Unix System What to Do? In this section, you will learn how to create a web interface for them, using the capabilities of the standard Go library. The name of the new Go source code file is kvWeb.go, and it will be presented in six parts.

The first difference between the Go code of kvWeb.go and www.go, developed earlier in this chapter, is that kvWeb.go uses the http.NewServeMux type for dealing with HTTP requests because it is much more versatile for nontrivial web applications.

The first part of kvWeb.go is as follows:

package main import ( "encoding/gob" "fmt" "html/template" "net/http" ...

Get Mastering Go now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.