Add remoteAddr information (#20)

This commit is contained in:
Michael
2019-09-03 11:40:33 +02:00
committed by Ludovic Fernandez
parent 48ed709a3a
commit 5e438f6f9e

9
app.go
View File

@ -63,7 +63,7 @@ func main() {
func benchHandler(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Connection", "keep-alive")
w.Header().Set("Content-Type", "text/plain")
fmt.Fprint(w, "1")
_, _ = fmt.Fprint(w, "1")
}
func echoHandler(w http.ResponseWriter, r *http.Request) {
@ -149,7 +149,7 @@ func whoamiHandler(w http.ResponseWriter, req *http.Request) {
}
hostname, _ := os.Hostname()
fmt.Fprintln(w, "Hostname:", hostname)
_, _ = fmt.Fprintln(w, "Hostname:", hostname)
ifaces, _ := net.Interfaces()
for _, i := range ifaces {
@ -163,10 +163,11 @@ func whoamiHandler(w http.ResponseWriter, req *http.Request) {
case *net.IPAddr:
ip = v.IP
}
fmt.Fprintln(w, "IP:", ip)
_, _ = fmt.Fprintln(w, "IP:", ip)
}
}
_, _ = fmt.Fprintln(w, "RemoteAddr:", req.RemoteAddr)
if err := req.Write(w); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
@ -204,9 +205,11 @@ func apiHandler(w http.ResponseWriter, req *http.Request) {
case *net.IPAddr:
ip = v.IP
}
if ip != nil {
data.IP = append(data.IP, ip.String())
}
}
}
if err := json.NewEncoder(w).Encode(data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)