add handler to return IP address. for ec2 wiring.

Change-Id: I346ba2764166b507dd96530061eb64bcbdc09bad
This commit is contained in:
Brad Fitzpatrick 2011-11-28 17:52:58 -05:00
parent b223044009
commit 43cd36a7f2
1 changed files with 17 additions and 1 deletions

View File

@ -279,13 +279,13 @@ func main() {
})
}
mux.Handle("/r/", gerritHandler)
mux.HandleFunc("/debugz/ip", ipHandler)
testCgi := &cgi.Handler{Path: filepath.Join(*root, "test.cgi"),
Root: "/test.cgi",
}
mux.Handle("/test.cgi", testCgi)
mux.Handle("/test.cgi/foo", testCgi)
mux.Handle("/code", http.RedirectHandler("/code/", http.StatusFound))
if *gitwebScript != "" {
env := os.Environ()
@ -365,3 +365,19 @@ func rsyncFromGerrit(dest string) {
time.Sleep(10e9)
}
}
func ipHandler(w http.ResponseWriter, r *http.Request) {
out, _ := exec.Command("ip", "-f", "inet", "addr", "show", "dev", "eth0").Output()
str := string(out)
pos := strings.Index(str, "inet ")
if pos == -1 {
return
}
str = str[pos + 5:]
pos = strings.Index(str, "/")
if pos == -1 {
return
}
str = str[:pos]
w.Write([]byte(str))
}