From 5e438f6f9eb6df4717b8cca2b1327c667a2900fd Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 3 Sep 2019 11:40:33 +0200 Subject: [PATCH] Add remoteAddr information (#20) --- app.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index b59f993..9eeb58c 100644 --- a/app.go +++ b/app.go @@ -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,7 +205,9 @@ func apiHandler(w http.ResponseWriter, req *http.Request) { case *net.IPAddr: ip = v.IP } - data.IP = append(data.IP, ip.String()) + if ip != nil { + data.IP = append(data.IP, ip.String()) + } } }