amuse.git

commit 14184a50d72c1514833d683a3627a588c8a5d49e

Author: Adam <git@apiote.tk>

add address to config

 config/config.go | 3 +++
 main.go | 4 ++++
 router.go | 6 +++---


diff --git a/config/config.go b/config/config.go
index 598b4d795a863a4bc89552d3d78341ba58c04281..37411a498d1b7df12b9e3bda870dbd76e674d015 100644
--- a/config/config.go
+++ b/config/config.go
@@ -11,6 +11,7 @@ var (
 	OpenRegistration      = false
 	DataHome              = "/usr/local/amuse"
 	Port             uint = 5008
+	Address               = "127.0.0.1"
 )
 
 func ReadConfig(path string) error {
@@ -36,6 +37,8 @@ 		case "OpenRegistration":
 			OpenRegistration = value == "true"
 		case "DataHome":
 			DataHome = value
+		case "Address":
+			Address = value
 		case "Port":
 			fmt.Sscanf(value, "%d", &Port)
 		}




diff --git a/main.go b/main.go
index adf274c333aff32acea1956088785396345c704e..c51ea0cbde6c478d2b602e08d972035e2af0b8ff 100644
--- a/main.go
+++ b/main.go
@@ -12,6 +12,7 @@ )
 
 func main() {
 	port := flag.Int("p", -1, "port to run amuse on")
+	address := flag.String("a", "", "address to run amuse on")
 	dataHome := flag.String("d", "", "data directory")
 	manage := flag.String("m", "", "manage command")
 	configPath := flag.String("c", "/etc/amuse.toml", "configPath")
@@ -23,6 +24,9 @@ 		config.DataHome = *dataHome
 	}
 	if *port > 0 {
 		config.Port = uint(*port)
+	}
+	if *address != "" {
+		config.Address = *address
 	}
 
 	db.Migrate()




diff --git a/router.go b/router.go
index da06eb9b4447a8d9e43979067d7f017d4e3f12b9..a91c99047a40de7adf27ce158b1c5cac326afc05 100644
--- a/router.go
+++ b/router.go
@@ -537,7 +537,7 @@ 	render(loggedout, err, w, acceptLanguages, mimetype)
 }
 
 func route(port uint) {
-	portStr := fmt.Sprintf(":%d", port)
+	address := fmt.Sprintf("%s:%d", config.Address, port)
 
 	http.HandleFunc("/", index)
 	http.HandleFunc("/static/", static)
@@ -554,8 +554,8 @@ 	http.HandleFunc("/login", login)
 	http.HandleFunc("/signup", signup)
 	http.HandleFunc("/signedup", signedup)
 	http.HandleFunc("/loggedout", loggedout)
-	fmt.Printf("running on %s\n", portStr)
-	e := http.ListenAndServe(portStr, nil)
+	fmt.Printf("running on %s\n", address)
+	e := http.ListenAndServe(address, nil)
 	if e != nil {
 		fmt.Println(e)
 	}