2
0

Conform closer to database/sql style and add no rows test

This commit is contained in:
Jack Christensen
2014-07-11 08:16:21 -05:00
parent 566d713285
commit 01f261c71c
3 changed files with 48 additions and 20 deletions
+5 -3
View File
@@ -45,11 +45,13 @@ func afterConnect(conn *pgx.Conn) (err error) {
func getUrlHandler(w http.ResponseWriter, req *http.Request) {
var url string
if err := pool.QueryRow("getUrl", req.URL.Path).Scan(&url); err == nil {
err := pool.QueryRow("getUrl", req.URL.Path).Scan(&url)
switch err {
case nil:
http.Redirect(w, req, url, http.StatusSeeOther)
} else if _, ok := err.(pgx.NotSingleRowError); ok {
case pgx.ErrNoRows:
http.NotFound(w, req)
} else {
default:
http.Error(w, "Internal server error", http.StatusInternalServerError)
}
}