You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
451 B

package main
import (
"IPRegion/global"
"IPRegion/ip2region"
"encoding/json"
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", IPHandle)
http.ListenAndServe(":8080", nil)
}
func IPHandle(w http.ResponseWriter, req *http.Request) {
address := req.FormValue("address")
var ipInfo ip2region.IpInfo
if address != "" {
ipInfo, _ = GetIPInfo(address, global.SearchType)
}
res, _ := json.Marshal(ipInfo)
fmt.Fprintln(w, string(res))
}