mirror of
https://github.com/jimeh/cloudflare-dyndns.git
synced 2026-02-19 10:56:42 +00:00
Initial commit
This commit is contained in:
36
vendor/github.com/cloudflare/cloudflare-go/ips.go
generated
vendored
Normal file
36
vendor/github.com/cloudflare/cloudflare-go/ips.go
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
package cloudflare
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
/*
|
||||
IPs gets a list of CloudFlare's IP ranges
|
||||
|
||||
This does not require logging in to the API.
|
||||
|
||||
API reference:
|
||||
https://api.cloudflare.com/#cloudflare-ips
|
||||
GET /client/v4/ips
|
||||
*/
|
||||
func IPs() (IPRanges, error) {
|
||||
resp, err := http.Get(apiURL + "/ips")
|
||||
if err != nil {
|
||||
return IPRanges{}, errors.Wrap(err, "HTTP request failed")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return IPRanges{}, errors.Wrap(err, "Response body could not be read")
|
||||
}
|
||||
var r IPsResponse
|
||||
err = json.Unmarshal(body, &r)
|
||||
if err != nil {
|
||||
return IPRanges{}, errors.Wrap(err, errUnmarshalError)
|
||||
}
|
||||
return r.Result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user