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

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

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

func ip(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/plain")
	addr, _, err := net.SplitHostPort(r.RemoteAddr)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	io.WriteString(w, addr)
}