Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address non-Close errors identified by errcheck #107

Merged
merged 3 commits into from
May 26, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix errcheck errors in app
  • Loading branch information
peterbourgon committed May 26, 2015
commit 84454d1ba1b46218c82fc82ec7391900a16e5310
9 changes: 7 additions & 2 deletions app/api_topology.go
Original file line number Diff line number Diff line change
@@ -59,7 +59,10 @@ func makeTopologyHandlers(

// Websocket for the full topology. This route overlaps with the next.
get.HandleFunc(base+"/ws", func(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
if err := r.ParseForm(); err != nil {
respondWith(w, http.StatusInternalServerError, err.Error())
return
}
loop := websocketLoop
if t := r.Form.Get("t"); t != "" {
var err error
@@ -140,7 +143,9 @@ func handleWebsocket(
diff := report.TopoDiff(previousTopo, newTopo)
previousTopo = newTopo

conn.SetWriteDeadline(time.Now().Add(websocketTimeout))
if err := conn.SetWriteDeadline(time.Now().Add(websocketTimeout)); err != nil {
return
}
if err := conn.WriteJSON(diff); err != nil {
return
}
11 changes: 0 additions & 11 deletions app/main.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"log/syslog"
"net/http"
@@ -28,7 +27,6 @@ func main() {
probes = flag.String("probes", strings.Join(defaultProbes, ","), "list of probe endpoints, comma separated")
batch = flag.Duration("batch", 1*time.Second, "batch interval")
window = flag.Duration("window", 15*time.Second, "window")
pidfile = flag.String("pidfile", "", "write PID file")
listen = flag.String("http.address", ":"+strconv.Itoa(xfer.AppPort), "webserver listen address")
)
flag.Parse()
@@ -57,15 +55,6 @@ func main() {
log.SetOutput(f)
}

if *pidfile != "" {
err := ioutil.WriteFile(*pidfile, []byte(fmt.Sprint(os.Getpid())), 0644)
if err != nil {
log.Print(err)
return
}
defer os.Remove(*pidfile)
}

log.Printf("app starting, version %s", version)

// Collector deals with the probes, and generates merged reports.
5 changes: 4 additions & 1 deletion app/server_helpers.go
Original file line number Diff line number Diff line change
@@ -2,12 +2,15 @@ package main

import (
"encoding/json"
"log"
"net/http"
)

func respondWith(w http.ResponseWriter, code int, response interface{}) {
w.Header().Set("Content-Type", "application/json")
w.Header().Add("Cache-Control", "no-cache")
w.WriteHeader(code)
json.NewEncoder(w).Encode(response)
if err := json.NewEncoder(w).Encode(response); err != nil {
log.Print(err)
}
}