geo_lookup

Functionin geocompute-sdk-cpp 0.7.0View source
fastly::expected<std::optional<Geo>> fastly::geo::geo_lookup(std::string_view ip)

Look up the geographic data associated with a particular IP address.

Returns std::nullopt if no geographic data is available, such as when the IP address is reserved for private use.

Examples

To get geographic information for the downstream client:

Parameters

ip: std::string_view

Returns

fastly::expected<std::optional<Geo>>
auto client_ip{fastly::Request::from_client().get_client_ip_addr().value()};
auto geo{fastly::geo::geo_lookup(client_ip).value()};
if (geo.conn_type() == fastly::geo::ConnType::Satellite) {
std::cout << "receiving a request from outer space 🛸";
}