main.rs 852 字节
Newer Older
G
gongzhengyang 已提交
1 2 3 4
use std::env;
use std::io::Write;
use std::time::Instant;

5 6 7
mod cmd;

fn main() {
G
gongzhengyang 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
    env::var("XDB_FILEPATH").unwrap_or_else(|_| {
        let matches = cmd::get_matches();
        let xdb_filepath = matches.get_one::<String>("xdb").unwrap();
        env::set_var("XDB_FILEPATH", xdb_filepath);
        xdb_filepath.to_owned()
    });
    search::global_searcher();
    println!("ip2region xdb searcher test program, type `quit` to exit");
    loop {
        print!("ip2region>> ");
        std::io::stdout().flush().unwrap();
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        if line.contains("quit") {
            break
        }
        let now = Instant::now();
        let result = search::search_by_ip(line.trim());
        println!("region: {:?}, took: {:?}", result, now.elapsed());
    }

29
}