Feat: location data at /v1/publicip/ip

This commit is contained in:
Quentin McGaw (desktop)
2021-09-05 22:54:10 +00:00
parent 82ac568ee3
commit f9cb71027c
9 changed files with 62 additions and 42 deletions

View File

@@ -10,21 +10,16 @@ import (
"strings"
"github.com/qdm12/gluetun/internal/constants"
"github.com/qdm12/gluetun/internal/publicip/models"
)
type Result struct {
Region string `json:"region"`
Country string `json:"country"`
City string `json:"city"`
}
var (
ErrTooManyRequests = errors.New("too many requests sent for this month")
ErrBadHTTPStatus = errors.New("bad HTTP status received")
)
func Info(ctx context.Context, client *http.Client, ip net.IP) ( //nolint:interfacer
result Result, err error) {
result models.IPInfoData, err error) {
const baseURL = "https://ipinfo.io/"
url := baseURL + ip.String()
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)