Skip to content

Commit e96064e

Browse files
committed
End functions when errors occur, rather than nesting inside of if statements.
1 parent 519e1d8 commit e96064e

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

internal/server/server.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,30 @@ import (
2929
// helpHandler returns the contents of `adb help` as plaintext.
3030
func helpHandler(response http.ResponseWriter, request *http.Request) {
3131
adbRun := adb.NewRun("help")
32-
if err := proxyAdbRun(response, &adbRun); err == nil {
33-
response.Header().Set("Content-Type", "text/plain; charset=utf-8")
34-
response.WriteHeader(http.StatusOK)
35-
36-
response.Write(adbRun.StdOut)
32+
if err := proxyAdbRun(response, &adbRun); err != nil {
33+
return
3734
}
35+
36+
response.Header().Set("Content-Type", "text/plain; charset=utf-8")
37+
response.WriteHeader(http.StatusOK)
38+
response.Write(adbRun.StdOut)
3839
}
3940

4041
// devicesHandler returns the contents of `adb devices -l` as JSON.
4142
// TODO: Add example JSON here.
4243
func devicesHandler(response http.ResponseWriter, request *http.Request) {
4344
adbRun := adb.NewRun("devices", "-l")
44-
if err := proxyAdbRun(response, &adbRun); err == nil {
45-
deviceList, err := adb.ParseDeviceList(adbRun.StdOut)
46-
if err != nil {
47-
// TODO: Make a 502 helper method
48-
return
49-
}
50-
51-
writeResponseAsJSON(response, deviceList)
45+
if err := proxyAdbRun(response, &adbRun); err != nil {
46+
return
5247
}
48+
49+
deviceList, err := adb.ParseDeviceList(adbRun.StdOut)
50+
if err != nil {
51+
// TODO: Make a 502 helper method
52+
return
53+
}
54+
55+
writeResponseAsJSON(response, deviceList)
5356
}
5457

5558
// proxyAdbRun executes the command stored in the provided adb.Run instance and handles

0 commit comments

Comments
 (0)