Fix panic with HTTP serve initialization problems.

This commit is contained in:
Vincent Batoufflet 2014-01-26 10:48:00 +01:00 committed by spf13
parent 0ce6f05f59
commit ff9f6e1b2a

View file

@ -17,6 +17,7 @@ import (
"fmt" "fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"net/http" "net/http"
"os"
"strconv" "strconv"
"strings" "strings"
) )
@ -83,5 +84,10 @@ func serve(port int) {
} }
fmt.Println("Press ctrl+c to stop") fmt.Println("Press ctrl+c to stop")
panic(http.ListenAndServe(":"+strconv.Itoa(port), http.FileServer(http.Dir(Config.GetAbsPath(Config.PublishDir)))))
err := http.ListenAndServe(":"+strconv.Itoa(port), http.FileServer(http.Dir(Config.GetAbsPath(Config.PublishDir))))
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error())
os.Exit(1)
}
} }