2 Commits

Author SHA1 Message Date
27713d1e8d Update to go1.12 (#21) 2019-09-03 11:41:03 +02:00
5e438f6f9e Add remoteAddr information (#20) 2019-09-03 11:40:33 +02:00
3 changed files with 10 additions and 5 deletions

View File

@ -1,4 +1,4 @@
FROM golang:1.11 as builder
FROM golang:1.12 as builder
WORKDIR /go/whoami
COPY . .
RUN make build

11
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,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())
}
}
}

2
go.mod
View File

@ -1,3 +1,5 @@
module github.com/containous/whoami
go 1.12
require github.com/gorilla/websocket v1.2.0