Merge pull request #9 from arnaldomf/change_ip_bind

Change IP bind
This commit is contained in:
GWoo
2015-11-10 14:42:55 -08:00
4 changed files with 13 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ import (
)
type Config struct {
IP string
Port string
Username string
Password string

View File

@@ -133,6 +133,9 @@ func setConfig() {
if config.Port == "" {
config.Port = "2224"
}
if config.IP == "" {
config.IP = "0.0.0.0"
}
}
func host() string {

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", 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", 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 {