Browse Source

main: not use loop variable in goroutine in loop body

Because loop variable are reused in following loops.
Yicheng Qin 11 years ago
parent
commit
7a698be6a3
1 changed files with 6 additions and 3 deletions
  1. 6 3
      main.go

+ 6 - 3
main.go

@@ -220,8 +220,9 @@ func startEtcd() {
 		}
 		}
 
 
 		// Start the peer server in a goroutine
 		// Start the peer server in a goroutine
+		urlStr := u.String()
 		go func() {
 		go func() {
-			log.Print("Listening for peers on ", u.String())
+			log.Print("Listening for peers on ", urlStr)
 			log.Fatal(http.Serve(l, ph))
 			log.Fatal(http.Serve(l, ph))
 		}()
 		}()
 	}
 	}
@@ -233,8 +234,9 @@ func startEtcd() {
 			log.Fatal(err)
 			log.Fatal(err)
 		}
 		}
 
 
+		urlStr := u.String()
 		go func() {
 		go func() {
-			log.Print("Listening for client requests on ", u.String())
+			log.Print("Listening for client requests on ", urlStr)
 			log.Fatal(http.Serve(l, ch))
 			log.Fatal(http.Serve(l, ch))
 		}()
 		}()
 	}
 	}
@@ -268,8 +270,9 @@ func startProxy() {
 			log.Fatal(err)
 			log.Fatal(err)
 		}
 		}
 
 
+		host := u.Host
 		go func() {
 		go func() {
-			log.Print("Listening for client requests on ", u.Host)
+			log.Print("Listening for client requests on ", host)
 			log.Fatal(http.Serve(l, ph))
 			log.Fatal(http.Serve(l, ph))
 		}()
 		}()
 	}
 	}