feat(publicip): cloudflare API support (#2502)

This commit is contained in:
Jeremy Lin
2024-10-06 06:30:33 -07:00
committed by GitHub
parent 99e9bc87cf
commit cbdd1a933c
3 changed files with 98 additions and 1 deletions

View File

@@ -19,6 +19,7 @@ type API interface {
type Provider string
const (
Cloudflare Provider = "cloudflare"
IPInfo Provider = "ipinfo"
IP2Location Provider = "ip2location"
)
@@ -26,6 +27,8 @@ const (
func New(provider Provider, client *http.Client, token string) ( //nolint:ireturn
a API, err error) {
switch provider {
case Cloudflare:
return newCloudflare(client), nil
case IPInfo:
return newIPInfo(client, token), nil
case IP2Location:
@@ -41,12 +44,14 @@ var (
func ParseProvider(s string) (provider Provider, err error) {
switch strings.ToLower(s) {
case "cloudflare":
return Cloudflare, nil
case "ipinfo":
return IPInfo, nil
case "ip2location":
return IP2Location, nil
default:
return "", fmt.Errorf(`%w: %q can only be "ipinfo" or "ip2location"`,
return "", fmt.Errorf(`%w: %q can only be "cloudflare", "ipinfo", or "ip2location"`,
ErrProviderNotValid, s)
}
}