1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::collections::HashMap;
use std::path::Path;
use std::fs::File;
use std::error::Error;
use std::io::BufReader;
use std::io::prelude::*;

pub mod actor;
mod log_entry;
mod http;
mod hash_utils;

mod nginx;

pub fn process(logfile: &str) -> Result<HashMap<String, actor::Actor>, String> {
    let path = Path::new(logfile);
    let file_handle = match File::open(&path) {
        Err(why) => {
            return Err(format!("Could not open {} : {}", path.display(), Error::description(&why)));
        },
        Ok(file) => file,
    };

    let reader = BufReader::new(file_handle);
    let mut actors = HashMap::<String, actor::Actor>::new();
    for line in reader.lines() {
        match line {
            Ok(line) => nginx::process(&mut actors, &line),
            Err(e)   => return Err(format!("ERROR {}", e)),
        }
    }

    return Ok(actors);
}