Added /mapping entry point.
This commit is contained in:
parent
9fb539eb91
commit
8f908cadd4
16
main.go
16
main.go
|
@ -107,6 +107,22 @@ func main() {
|
||||||
fmt.Fprintln(resp, "Allocated CDN node for you:", server)
|
fmt.Fprintln(resp, "Allocated CDN node for you:", server)
|
||||||
fmt.Fprintln(resp)
|
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()
|
ipgeo.Init()
|
||||||
http.ListenAndServe("0.0.0.0:8086", nil)
|
http.ListenAndServe("0.0.0.0:8086", nil)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue