我正在尝试围绕 Scala 进行研究,到目前为止,我发现它非常具有挑战性。我找到了这个库(https://github.com/snowplow/scala-maxmind-geoip),我过去使用 Python 来查找基于 IP 地址的国家/地区等内容。
所以这个例子很简单
import com.snowplowanalytics.maxmind.geoip.IpGeo
val ipGeo = IpGeo(dbFile = "/opt/maxmind/GeoLiteCity.dat", memCache = false, lruCache = 20000)
for (loc <- ipGeo.getLocation("213.52.50.8")) {
println(loc.countryCode) // => "NO"
println(loc.countryName) // => "Norway"
}
并且文档显示
getLocation(ip) 方法返回一个 IpLocation 案例类
那么,如果它是一个案例类,为什么这不起作用呢?
val loc = ipGeo.getLocation("213.52.50.8")
println(loc.countryCode)
毕竟我能做到
case class Team(team: String, country: String)
val u = Team("Barcelon", "Spain")
scala> u.country
res5: String = Spain
感谢您的时间!