summaryrefslogtreecommitdiff
path: root/ip.go
blob: 787c511c3d33e9b735918dc5a07d246618d61923 (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 (
	"fmt"
	"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
	}
	fmt.Fprintln(w, addr)
}