2021-02-02 12:05:47 +01:00
|
|
|
package geolocate
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
2022-01-05 17:17:20 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/httpx"
|
2022-01-03 13:53:23 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/model"
|
2021-02-02 12:05:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type avastResponse struct {
|
|
|
|
IP string `json:"ip"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func avastIPLookup(
|
|
|
|
ctx context.Context,
|
|
|
|
httpClient *http.Client,
|
2022-01-03 13:53:23 +01:00
|
|
|
logger model.Logger,
|
2021-02-02 12:05:47 +01:00
|
|
|
userAgent string,
|
|
|
|
) (string, error) {
|
|
|
|
var v avastResponse
|
2022-01-05 14:15:42 +01:00
|
|
|
err := (&httpx.APIClientTemplate{
|
2021-02-02 12:05:47 +01:00
|
|
|
BaseURL: "https://ip-info.ff.avast.com",
|
|
|
|
HTTPClient: httpClient,
|
|
|
|
Logger: logger,
|
|
|
|
UserAgent: userAgent,
|
2022-01-05 16:26:51 +01:00
|
|
|
}).WithBodyLogging().Build().GetJSON(ctx, "/v1/info", &v)
|
2021-02-02 12:05:47 +01:00
|
|
|
if err != nil {
|
|
|
|
return DefaultProbeIP, err
|
|
|
|
}
|
|
|
|
return v.IP, nil
|
|
|
|
}
|