diff options
author | Mario Krehl <mario-krehl@gmx.de> | 2017-12-10 10:44:33 +0100 |
---|---|---|
committer | Mario Krehl <mario-krehl@gmx.de> | 2017-12-10 10:44:33 +0100 |
commit | 1b2fbca7d98223eb42ebfce6c4fb392b094aedca (patch) | |
tree | 9545c29134b5944f2b141a646742820c50638b78 | |
parent | f818ed5482c6a76d19adba8f0d10f780f13fe570 (diff) |
Add serde strcuts for json deserialization (api.rs)
-rw-r--r-- | src/api.rs | 62 | ||||
-rw-r--r-- | src/main.rs | 3 |
2 files changed, 64 insertions, 1 deletions
diff --git a/src/api.rs b/src/api.rs new file mode 100644 index 0000000..3f8b234 --- /dev/null +++ b/src/api.rs @@ -0,0 +1,62 @@ +use chrono::prelude::*; +use serde_json; + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy)] +pub struct Range { + pub from: DateTime<Utc>, + pub to: DateTime<Utc>, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Target { + pub target: String, + #[serde(rename = "refId")] pub ref_id: String, + #[serde(rename = "type")] pub _type: String, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Query { + pub range: Range, + #[serde(rename = "intervalMs")] pub interval_ms: i32, + #[serde(rename = "maxDataPoints")] pub max_data_points: i32, + pub format: String, + pub targets: Vec<Target>, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +#[serde(untagged)] +pub enum TargetData { + Series(Series), + Table(Table), +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Series { + pub target: String, + pub datapoints: Vec<[u64; 2]>, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Column { + pub text: String, + #[serde(rename = "type")] pub _type: String, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Table { + pub columns: Vec<Column>, + #[serde(rename = "type")] pub _type: String, + pub rows: Vec<Vec<serde_json::Value>>, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct Search { + pub target: String, +} + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct SearchResponse(pub Vec<String>); + +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +pub struct QueryResponse(pub Vec<TargetData>); + diff --git a/src/main.rs b/src/main.rs index 22e2dc1..6137187 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,8 +23,9 @@ use rocket::State; use rocket_contrib::Json; use simplelog::{SimpleLogger, LogLevelFilter, Config as LogConfig}; -mod error; +mod api; mod config; +mod error; use config::Config; #[get("/")] |