diff --git a/ip/resolver/manager.go b/ip/resolver/manager.go index 136bc8f..347f143 100644 --- a/ip/resolver/manager.go +++ b/ip/resolver/manager.go @@ -50,4 +50,15 @@ func init() { ServiceName: "icanhazip", Url: "https://icanhazip.com", }) + + Provide(&httpres.Service{ + ServiceName: "ipify", + Url: "https://api.ipify.org", + }) + + Provide(&httpres.Service{ + ServiceName: "myip", + Url: "https://api.myip.com", + Decoder: MyIPDecoder, + }) } diff --git a/ip/resolver/myip.go b/ip/resolver/myip.go new file mode 100644 index 0000000..b7b912d --- /dev/null +++ b/ip/resolver/myip.go @@ -0,0 +1,20 @@ +package resolver + +import ( + "encoding/json" + "io" +) + +func MyIPDecoder(r io.Reader) ([]byte, error) { + var v struct { + Ip string `json:"ip"` + Country string `json:"country"` + Cc string `json:"cc"` + } + var val []byte + err := json.NewDecoder(r).Decode(&v) + if err == nil { + val = []byte(v.Ip) + } + return val, err +}