Added /getMapping API.
This commit is contained in:
parent
8f908cadd4
commit
1018ff016f
13
main.go
13
main.go
|
@ -16,7 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
errIPv4Only = "Navigator works for IPv4 only :)"
|
errIPv4Only = "Navigator works for valid IPv4 only :)"
|
||||||
)
|
)
|
||||||
|
|
||||||
type errorMessage struct {
|
type errorMessage struct {
|
||||||
|
@ -123,6 +123,17 @@ func main() {
|
||||||
server := mapping.Get(host)
|
server := mapping.Get(host)
|
||||||
fmt.Fprint(resp, server)
|
fmt.Fprint(resp, server)
|
||||||
})
|
})
|
||||||
|
http.HandleFunc("/getMapping", func(resp http.ResponseWriter, req *http.Request) {
|
||||||
|
ip := req.FormValue("ip")
|
||||||
|
if net.ParseIP(ip).To4() == nil {
|
||||||
|
responseWithError(resp, http.StatusBadRequest, errIPv4Only)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.Header().Set("Content-Type", "text/plain")
|
||||||
|
resp.WriteHeader(http.StatusOK)
|
||||||
|
server := mapping.Get(ip)
|
||||||
|
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