summaryrefslogtreecommitdiff
path: root/ip.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-04-24 01:18:42 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-04-24 01:18:42 +0200
commitbcc057616988fd86fedfc89d3f66da8219282b4d (patch)
treefe3a1bed95406e5d9b4cab1d4fb8e13746679194 /ip.go
parentd0af9d61887352e673a2bcb87787f7d3979c787f (diff)
Resolve hostname, handle errors
Diffstat (limited to 'ip.go')
-rw-r--r--ip.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/ip.go b/ip.go
index 278d472..f3ec3f1 100644
--- a/ip.go
+++ b/ip.go
@@ -11,6 +11,16 @@ func init() {
}
func ip(w http.ResponseWriter, r *http.Request) {
- host, _, _ := net.SplitHostPort(r.RemoteAddr)
+ addr, _, err := net.SplitHostPort(r.RemoteAddr)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ fmt.Fprintln(w, addr)
+ host, err := net.LookupAddr(addr)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
fmt.Fprintln(w, host)
}