diff --git a/doc/articles/wiki/final-noclosure.go b/doc/articles/wiki/final-noclosure.go index d72ca805b87..b4ce2557426 100644 --- a/doc/articles/wiki/final-noclosure.go +++ b/doc/articles/wiki/final-noclosure.go @@ -8,6 +8,7 @@ import ( "errors" "html/template" "io/ioutil" + "log" "net/http" "regexp" ) @@ -98,5 +99,5 @@ func main() { http.HandleFunc("/view/", viewHandler) http.HandleFunc("/edit/", editHandler) http.HandleFunc("/save/", saveHandler) - http.ListenAndServe(":8080", nil) + log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/doc/articles/wiki/final-noerror.go b/doc/articles/wiki/final-noerror.go index 86d8da751f9..42a22da9dd8 100644 --- a/doc/articles/wiki/final-noerror.go +++ b/doc/articles/wiki/final-noerror.go @@ -7,6 +7,7 @@ package main import ( "html/template" "io/ioutil" + "log" "net/http" ) @@ -49,5 +50,5 @@ func viewHandler(w http.ResponseWriter, r *http.Request) { func main() { http.HandleFunc("/view/", viewHandler) http.HandleFunc("/edit/", editHandler) - http.ListenAndServe(":8080", nil) + log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/doc/articles/wiki/final-parsetemplate.go b/doc/articles/wiki/final-parsetemplate.go index 5ff8bf60c5b..a9aa7f28943 100644 --- a/doc/articles/wiki/final-parsetemplate.go +++ b/doc/articles/wiki/final-parsetemplate.go @@ -7,6 +7,7 @@ package main import ( "html/template" "io/ioutil" + "log" "net/http" "regexp" ) @@ -87,5 +88,5 @@ func main() { http.HandleFunc("/view/", makeHandler(viewHandler)) http.HandleFunc("/edit/", makeHandler(editHandler)) http.HandleFunc("/save/", makeHandler(saveHandler)) - http.ListenAndServe(":8080", nil) + log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/doc/articles/wiki/final-template.go b/doc/articles/wiki/final-template.go index 719157da954..7ea480e50a9 100644 --- a/doc/articles/wiki/final-template.go +++ b/doc/articles/wiki/final-template.go @@ -7,6 +7,7 @@ package main import ( "html/template" "io/ioutil" + "log" "net/http" ) @@ -61,5 +62,5 @@ func main() { http.HandleFunc("/view/", viewHandler) http.HandleFunc("/edit/", editHandler) http.HandleFunc("/save/", saveHandler) - http.ListenAndServe(":8080", nil) + log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/doc/articles/wiki/final-test.patch b/doc/articles/wiki/final-test.patch index 499ad789b31..510825b319c 100644 --- a/doc/articles/wiki/final-test.patch +++ b/doc/articles/wiki/final-test.patch @@ -16,7 +16,7 @@ http.HandleFunc("/edit/", makeHandler(editHandler)) http.HandleFunc("/save/", makeHandler(saveHandler)) -! http.ListenAndServe(":8080", nil) +! log.Fatal(http.ListenAndServe(":8080", nil)) } --- 87,101 ---- http.HandleFunc("/edit/", makeHandler(editHandler)) diff --git a/doc/articles/wiki/final.go b/doc/articles/wiki/final.go index 139a3230108..0f6646ba879 100644 --- a/doc/articles/wiki/final.go +++ b/doc/articles/wiki/final.go @@ -7,6 +7,7 @@ package main import ( "html/template" "io/ioutil" + "log" "net/http" "regexp" ) @@ -85,5 +86,5 @@ func main() { http.HandleFunc("/edit/", makeHandler(editHandler)) http.HandleFunc("/save/", makeHandler(saveHandler)) - http.ListenAndServe(":8080", nil) + log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/doc/articles/wiki/http-sample.go b/doc/articles/wiki/http-sample.go index ac8cc4f2d67..9bc2084c672 100644 --- a/doc/articles/wiki/http-sample.go +++ b/doc/articles/wiki/http-sample.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "log" "net/http" ) @@ -11,5 +12,5 @@ func handler(w http.ResponseWriter, r *http.Request) { func main() { http.HandleFunc("/", handler) - http.ListenAndServe(":8080", nil) + log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/doc/articles/wiki/index.html b/doc/articles/wiki/index.html index b6b080df960..e5054f7bf74 100644 --- a/doc/articles/wiki/index.html +++ b/doc/articles/wiki/index.html @@ -213,6 +213,12 @@ worry about its second parameter, nil, for now.) This function will block until the program is terminated.

+

+ListenAndServe always returns an error, since it only returns when an +unexpected error occurs. +In order to log that error we wrap the function call with log.Fatal. +

+

The function handler is of the type http.HandlerFunc. It takes an http.ResponseWriter and an http.Request as diff --git a/doc/articles/wiki/notemplate.go b/doc/articles/wiki/notemplate.go index be214d1111d..0fda7a98ce5 100644 --- a/doc/articles/wiki/notemplate.go +++ b/doc/articles/wiki/notemplate.go @@ -7,6 +7,7 @@ package main import ( "fmt" "io/ioutil" + "log" "net/http" ) @@ -52,5 +53,5 @@ func editHandler(w http.ResponseWriter, r *http.Request) { func main() { http.HandleFunc("/view/", viewHandler) http.HandleFunc("/edit/", editHandler) - http.ListenAndServe(":8080", nil) + log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/doc/articles/wiki/part2.go b/doc/articles/wiki/part2.go index c0231693efb..30f9dcf146d 100644 --- a/doc/articles/wiki/part2.go +++ b/doc/articles/wiki/part2.go @@ -7,6 +7,7 @@ package main import ( "fmt" "io/ioutil" + "log" "net/http" ) @@ -37,5 +38,5 @@ func viewHandler(w http.ResponseWriter, r *http.Request) { func main() { http.HandleFunc("/view/", viewHandler) - http.ListenAndServe(":8080", nil) + log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/doc/articles/wiki/part3-errorhandling.go b/doc/articles/wiki/part3-errorhandling.go index bb4ecda84bb..34b13a60864 100644 --- a/doc/articles/wiki/part3-errorhandling.go +++ b/doc/articles/wiki/part3-errorhandling.go @@ -7,6 +7,7 @@ package main import ( "html/template" "io/ioutil" + "log" "net/http" ) @@ -69,5 +70,5 @@ func main() { http.HandleFunc("/view/", viewHandler) http.HandleFunc("/edit/", editHandler) http.HandleFunc("/save/", saveHandler) - http.ListenAndServe(":8080", nil) + log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/doc/articles/wiki/part3.go b/doc/articles/wiki/part3.go index 174f3abcd76..5e5d5056c49 100644 --- a/doc/articles/wiki/part3.go +++ b/doc/articles/wiki/part3.go @@ -7,6 +7,7 @@ package main import ( "html/template" "io/ioutil" + "log" "net/http" ) @@ -53,5 +54,5 @@ func main() { http.HandleFunc("/view/", viewHandler) http.HandleFunc("/edit/", editHandler) //http.HandleFunc("/save/", saveHandler) - http.ListenAndServe(":8080", nil) + log.Fatal(http.ListenAndServe(":8080", nil)) }