1. Following the Go Tour’s Web Servers section, I created the file: web-servers.go
Go
package main
import (
"fmt"
"log"
"net/http"
)
type Hello struct{}
func (h Hello) ServeHTTP(
w http.ResponseWriter,
r *http.Request) {
fmt.Fprint(w, "Hello!")
}
func main() {
var h Hello
err := http.ListenAndServe("localhost:4000", h)
if err != nil {
log.Fatal(err)
}
}
2. When accessing http://localhost:4000/, it prompted: This site can’t be reached, as shown in Figure 1.

3. After running go run web-servers.go in PowerShell, accessing http://localhost:4000/ again output: Hello!, as shown in Figure 2.

Plaintext
PS E:\wwwroot\go\methods> go run web-servers.go
