Checking for errors on ListenAndServe

This commit is contained in:
Arnaldo Mendonca
2015-11-09 23:11:30 -02:00
parent 53e87ff642
commit eedf754137
2 changed files with 9 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
ip = "127.0.0.1"
port = "2224"
username = "go"
password = "forever"

10
http.go
View File

@@ -17,12 +17,18 @@ func HttpServer() {
http.HandleFunc("/favicon.ico", http.NotFound)
http.HandleFunc("/", AuthHandler(Handler))
fmt.Printf("goforever serving port %s\n", config.Port)
fmt.Printf("goforever serving IP %s\n", config.IP)
bindAddress := fmt.Sprintf("%s:%s", config.IP, config.Port)
if isHttps() == false {
http.ListenAndServe(fmt.Sprintf("%s:%s", config.IP, config.Port), nil)
if err := http.ListenAndServe(bindAddress, nil); err != nil {
log.Fatal("ListenAndServe: ", err)
}
return
}
log.Printf("SSL enabled.\n")
http.ListenAndServeTLS(fmt.Sprintf("%s:%s", config.IP, config.Port), "cert.pem", "key.pem", nil)
if err := http.ListenAndServeTLS(bindAddress, "cert.pem", "key.pem", nil); err != nil {
log.Fatal("ListenAndServeTLS: ", err)
}
}
func isHttps() bool {