32 lines
560 B
Go
32 lines
560 B
Go
|
package geolocate
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/ooni/probe-cli/v3/internal/engine/internal/httpx"
|
||
|
)
|
||
|
|
||
|
type avastResponse struct {
|
||
|
IP string `json:"ip"`
|
||
|
}
|
||
|
|
||
|
func avastIPLookup(
|
||
|
ctx context.Context,
|
||
|
httpClient *http.Client,
|
||
|
logger Logger,
|
||
|
userAgent string,
|
||
|
) (string, error) {
|
||
|
var v avastResponse
|
||
|
err := (httpx.Client{
|
||
|
BaseURL: "https://ip-info.ff.avast.com",
|
||
|
HTTPClient: httpClient,
|
||
|
Logger: logger,
|
||
|
UserAgent: userAgent,
|
||
|
}).GetJSON(ctx, "/v1/info", &v)
|
||
|
if err != nil {
|
||
|
return DefaultProbeIP, err
|
||
|
}
|
||
|
return v.IP, nil
|
||
|
}
|