summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMario Krehl <mario-krehl@gmx.de>2017-12-10 10:22:51 +0100
committerMario Krehl <mario-krehl@gmx.de>2017-12-10 10:22:51 +0100
commitf818ed5482c6a76d19adba8f0d10f780f13fe570 (patch)
tree56161d46db0fd6221f09bcfbecb62ccc6b3365a2
parentf65bd7231a2a99305002c1d8dc5b42b90ed9779f (diff)
Add some dependencies und skeleton for rocket
-rw-r--r--Cargo.toml5
-rw-r--r--src/main.rs47
2 files changed, 31 insertions, 21 deletions
diff --git a/Cargo.toml b/Cargo.toml
index cf30ef4..c5ecaea 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,10 +4,15 @@ name = "aklog-server"
version = "0.1.0"
[dependencies]
+chrono = "0.4"
clap = "2"
+dimensioned = "0.6"
error-chain = "0.11"
log = "^0.3.8"
regex = "0.2"
+rocket = "0.3"
+rocket_codegen = "0.3"
+rocket_contrib = "0.3"
serde = "1"
serde_derive = "1"
serde_json = "1"
diff --git a/src/main.rs b/src/main.rs
index 38ad392..22e2dc1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,11 @@
#![recursion_limit = "1024"]
+#![feature(plugin)]
+#![plugin(rocket_codegen)]
+
extern crate clap;
+extern crate chrono;
+extern crate dimensioned;
#[macro_use]
extern crate error_chain;
#[macro_use]
@@ -14,12 +19,29 @@ use std::process::exit;
use std::fs::File;
use clap::{App, Arg};
+use rocket::State;
+use rocket_contrib::Json;
use simplelog::{SimpleLogger, LogLevelFilter, Config as LogConfig};
mod error;
mod config;
use config::Config;
+#[get("/")]
+fn index() -> &'static str {
+ "Hello there!"
+}
+
+#[post("/search", format = "application/json", data = "<data>")]
+fn search(data : Json<Search>, config: State<Config>) -> Json<SearchResponse> {
+
+}
+
+#[post("query", format = "application/json", data = "<data>")]
+fn query(data: Json<Query>, config: State<Config>) -> Result<Json<QueryResponse>> {
+
+}
+
fn main() {
let matches = App::new("aklog-server")
.version("0.1.0")
@@ -45,7 +67,6 @@ fn main() {
2 => SimpleLogger::init(LogLevelFilter::Debug, LogConfig::default()).unwrap(),
3 | _ => SimpleLogger::init(LogLevelFilter::Trace, LogConfig::default()).unwrap(),
};
-
debug!("Initialized logger");
let config_file = matches.value_of("config").unwrap();
@@ -56,25 +77,9 @@ fn main() {
exit(1);
},
};
- let items = config.items();
-
- let first_item = items.first().unwrap();
- let file = File::open(first_item.file()).unwrap();
- use std::io::BufReader;
- use std::io::BufRead;
- let bufreader = BufReader::new(file);
- let mut capturename_iter = first_item.regex().capture_names().skip(1);
- while let Some(Some(name)) = capturename_iter.next() {
- println!("Named Capture: {}", name);
- }
- let mut line_iter = bufreader.lines();
- while let Some(Ok(line)) = line_iter.next() {
- if first_item.regex().is_match(line.as_str()) {
- println!("{}", line);
- }
- else {
- println!("did not match");
- }
- }
+ rocket::ignite()
+ .manage(config)
+ .mount("/", routes![index, search, query])
+ .launch()
}