...単にjavaメソッド呼び出してるだけレベルだけども、今度はmaxminddb試してみておく。
Getting Startedで入れた環境で、Maxmind-DB-Reader-javaのinstall情報を元に.clojure/deps.ednに追記してclojure起動する。
:deps { org.clojure/clojure {:mvn/version "1.10.1"} com.maxmind.db/maxmind-db {:mvn/version "1.3.0"} }
sample.clj
(:import com.maxmind.db.Reader) (:import com.maxmind.db.NoCache) (:import java.io.File) (:import java.net.InetAddress) (def reader (new com.maxmind.db.Reader (new java.io.File "GeoLite2-ASN.mmdb") com.maxmind.db.Reader$FileMode/MEMORY_MAPPED (com.maxmind.db.NoCache/getInstance))) (println (.toString (.get reader (java.net.InetAddress/getByName "8.8.8.8"))))
実行例
nao@PC:~$ clojure sample.clj {"autonomous_system_organization":"Google LLC","autonomous_system_number":15169}
これができて、なにがいいか、どんなときに使えるか。まあ今のところルックアップ機能の一つの選択肢として覚えておく。*1*2