Addressed various points raised in review: error-handling, simplified Fprint call

This commit is contained in:
Bryan Boreham committed 2014-09-04 14:44:42 +01:00
1 parent 67d8220bdf
commit 04ca3d2469
2 files changed
+12 -5

No files matched your search

+6 -2
View File
@@ -6,6 +6,7 @@ import (
"crypto/sha256" "crypto/sha256"
"flag" "flag"
"fmt" "fmt"
"io"
"github.com/davecheney/profile" "github.com/davecheney/profile"
"log" "log"
"net" "net"
@@ -136,10 +137,13 @@ func main() {
func handleHttp(router *weave.Router) { func handleHttp(router *weave.Router) {
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, router.Status()) io.WriteString(w, router.Status())
}) })
address := fmt.Sprintf(":%d", weave.StatusPort) address := fmt.Sprintf(":%d", weave.StatusPort)
http.ListenAndServe(address, nil) err := http.ListenAndServe(address, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
} }
+6 -3
View File
@@ -80,16 +80,19 @@ case "$COMMAND" in
;; ;;
status) status)
DOCKERIP=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' weave) DOCKERIP=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' weave)
if [ -z "$DOCKERIP" ] ; then
echo "The weave container is not running." >&2
exit 1
fi
if command_exists wget ; then if command_exists wget ; then
wget -O - -q $DOCKERIP:6784/status wget -O - -q $DOCKERIP:6784/status
elif command_exists curl ; then elif command_exists curl ; then
curl $DOCKERIP:6784/status curl $DOCKERIP:6784/status
else else
echo "weave status needs either curl or wget to function" >&2 echo "Cannot find wget or curl. Install one of them for 'weave status' to function." >&2
exit 1 exit 1
fi fi
# return the status from the wget or curl command, so if they fail then we fail. exit 0
exit $?
;; ;;
run) run)
[ $# -gt 0 ] || usage [ $# -gt 0 ] || usage