# HG changeset patch # User drewp # Date 1378006342 25200 # Node ID 8329c3eddb08a2fe4b0c477d6e014741cb0d077c # Parent c80a23d86ea97c177644d8971fa6a95693d6152f use goweb response api Ignore-this: 48fa536486bbe388dd4c48620e601e7c darcs-hash:20130901033222-312f9-0b215977e26a2b53543252447c41f81564181dc9 diff -r c80a23d86ea9 -r 8329c3eddb08 service/laundry/laundry.go --- a/service/laundry/laundry.go Sat Aug 31 16:09:48 2013 -0700 +++ b/service/laundry/laundry.go Sat Aug 31 20:32:22 2013 -0700 @@ -119,14 +119,12 @@ } else if string(body) == "off" { level = 0 } else { - http.Error(c.HttpResponseWriter(), "body must be 'on' or 'off'", http.StatusBadRequest) - return nil + return goweb.Respond.With(c, http.StatusBadRequest, "body must be 'on' or 'off'") } hwio.DigitalWrite(pins.OutLed, level) pins.LastOutLed = level - http.Error(c.HttpResponseWriter(), "", http.StatusAccepted) - return nil + return goweb.Respond.WithStatusText(c, http.StatusAccepted) }) setStrike := func (level int) { @@ -142,13 +140,11 @@ level, err2 := strconv.Atoi(string(body[:])) if err2 != nil { - http.Error(c.HttpResponseWriter(), "body must be '0' or '1'", http.StatusBadRequest) - return nil + return goweb.Respond.With(c, http.StatusBadRequest, "body must be '0' or '1'") } setStrike(level) - http.Error(c.HttpResponseWriter(), "", http.StatusAccepted) - return nil + return goweb.Respond.WithStatusText(c, http.StatusAccepted) }) goweb.Map("PUT", "/strike/temporaryUnlock", func(c context.Context) error { @@ -170,14 +166,12 @@ time.Sleep(time.Duration(req.Seconds * float64(time.Second))) setStrike(0) }() - http.Error(c.HttpResponseWriter(), "", http.StatusAccepted) - return nil + return goweb.Respond.WithStatusText(c, http.StatusAccepted) }) goweb.Map("PUT", "/speaker/beep", func(c context.Context) error { // queue a beep - http.Error(c.HttpResponseWriter(), "", http.StatusAccepted) - return nil + return goweb.Respond.WithStatusText(c, http.StatusAccepted) })