diff --git a/main.go b/main.go index b85afdd..f9479b9 100644 --- a/main.go +++ b/main.go @@ -107,6 +107,22 @@ func main() { fmt.Fprintln(resp, "Allocated CDN node for you:", server) fmt.Fprintln(resp) }) + + http.HandleFunc("/mapping", func(resp http.ResponseWriter, req *http.Request) { + host, _, err := net.SplitHostPort(req.RemoteAddr) + if err != nil { + responseWithError(resp, http.StatusPreconditionFailed, errIPv4Only) + return + } + if net.ParseIP(host).To4() == nil { + responseWithError(resp, http.StatusPreconditionFailed, errIPv4Only) + return + } + resp.Header().Set("Content-Type", "text/plain") + resp.WriteHeader(http.StatusOK) + server := mapping.Get(host) + fmt.Fprint(resp, server) + }) ipgeo.Init() http.ListenAndServe("0.0.0.0:8086", nil) }