summaryrefslogtreecommitdiff
path: root/ip.go
blob: d3cd599d7bd3cdf5814bddf72cc1d0b0a67280fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package main

import (
	"io"
	"net/http"
	"strings"
)

func init() {
	http.HandleFunc("/ip", ip)
}

func ip(w http.ResponseWriter, r *http.Request) {
	ra := r.RemoteAddr
	if n := strings.Index(ra, ":"); n >= 0 {
		ra = ra[:n]
	}
	io.WriteString(w, ra)
}