"errors"
"html/template"
"io/ioutil"
+ "log"
"net/http"
"regexp"
)
http.HandleFunc("/view/", viewHandler)
http.HandleFunc("/edit/", editHandler)
http.HandleFunc("/save/", saveHandler)
- http.ListenAndServe(":8080", nil)
+ log.Fatal(http.ListenAndServe(":8080", nil))
}
import (
"html/template"
"io/ioutil"
+ "log"
"net/http"
)
func main() {
http.HandleFunc("/view/", viewHandler)
http.HandleFunc("/edit/", editHandler)
- http.ListenAndServe(":8080", nil)
+ log.Fatal(http.ListenAndServe(":8080", nil))
}
import (
"html/template"
"io/ioutil"
+ "log"
"net/http"
"regexp"
)
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))
}
import (
"html/template"
"io/ioutil"
+ "log"
"net/http"
)
http.HandleFunc("/view/", viewHandler)
http.HandleFunc("/edit/", editHandler)
http.HandleFunc("/save/", saveHandler)
- http.ListenAndServe(":8080", nil)
+ log.Fatal(http.ListenAndServe(":8080", nil))
}
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))
import (
"html/template"
"io/ioutil"
+ "log"
"net/http"
"regexp"
)
http.HandleFunc("/edit/", makeHandler(editHandler))
http.HandleFunc("/save/", makeHandler(saveHandler))
- http.ListenAndServe(":8080", nil)
+ log.Fatal(http.ListenAndServe(":8080", nil))
}
import (
"fmt"
+ "log"
"net/http"
)
func main() {
http.HandleFunc("/", handler)
- http.ListenAndServe(":8080", nil)
+ log.Fatal(http.ListenAndServe(":8080", nil))
}
This function will block until the program is terminated.
</p>
+<p>
+<code>ListenAndServe</code> 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 <code>log.Fatal</code>.
+</p>
+
<p>
The function <code>handler</code> is of the type <code>http.HandlerFunc</code>.
It takes an <code>http.ResponseWriter</code> and an <code>http.Request</code> as
import (
"fmt"
"io/ioutil"
+ "log"
"net/http"
)
func main() {
http.HandleFunc("/view/", viewHandler)
http.HandleFunc("/edit/", editHandler)
- http.ListenAndServe(":8080", nil)
+ log.Fatal(http.ListenAndServe(":8080", nil))
}
import (
"fmt"
"io/ioutil"
+ "log"
"net/http"
)
func main() {
http.HandleFunc("/view/", viewHandler)
- http.ListenAndServe(":8080", nil)
+ log.Fatal(http.ListenAndServe(":8080", nil))
}
import (
"html/template"
"io/ioutil"
+ "log"
"net/http"
)
http.HandleFunc("/view/", viewHandler)
http.HandleFunc("/edit/", editHandler)
http.HandleFunc("/save/", saveHandler)
- http.ListenAndServe(":8080", nil)
+ log.Fatal(http.ListenAndServe(":8080", nil))
}
import (
"html/template"
"io/ioutil"
+ "log"
"net/http"
)
http.HandleFunc("/view/", viewHandler)
http.HandleFunc("/edit/", editHandler)
//http.HandleFunc("/save/", saveHandler)
- http.ListenAndServe(":8080", nil)
+ log.Fatal(http.ListenAndServe(":8080", nil))
}