structs: reorganize
Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
parent
bab21a9bae
commit
09879a3cee
2 changed files with 20 additions and 20 deletions
|
@ -4,6 +4,8 @@ clients:
|
|||
write_metrics:
|
||||
- irradiance
|
||||
- temperature
|
||||
read_metrics:
|
||||
- weather.*
|
||||
auth:
|
||||
type: sha256
|
||||
hash: ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb # a
|
||||
|
@ -32,16 +34,9 @@ clients:
|
|||
auth:
|
||||
# ...
|
||||
|
||||
# Anonymous login
|
||||
- name: public_consumer
|
||||
read_metrics:
|
||||
- weather.*
|
||||
auth:
|
||||
type: anonymous
|
||||
|
||||
|
||||
config:
|
||||
opentsdb:
|
||||
url: http://opentsdb/api/
|
||||
url: http://192.168.30.2/api/
|
||||
server:
|
||||
port: 8080
|
||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -16,33 +16,38 @@ struct ClientData {
|
|||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct QSParams {
|
||||
struct QPutParams {
|
||||
token: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
struct OtsdbPutData {
|
||||
metric: String,
|
||||
value: StringIntFloat,
|
||||
timestamp: i64,
|
||||
tags: HashMap<String, StringIntFloat>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct QQueryParams {
|
||||
token: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(untagged)]
|
||||
enum OtsdbValue {
|
||||
enum StringIntFloat {
|
||||
String(String),
|
||||
Integer(i64),
|
||||
Float(f64),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
struct OtsdbData {
|
||||
metric: String,
|
||||
value: OtsdbValue,
|
||||
timestamp: i64,
|
||||
tags: HashMap<String, OtsdbValue>,
|
||||
}
|
||||
|
||||
const CONFIG_FILE: &str = "config.yaml";
|
||||
|
||||
#[actix_web::post("/put")]
|
||||
async fn put_post(
|
||||
shared: web::Data<ClientData>,
|
||||
qs: web::Query<QSParams>,
|
||||
body: web::Json<OtsdbData>,
|
||||
qs: web::Query<QPutParams>,
|
||||
body: web::Json<OtsdbPutData>,
|
||||
) -> impl Responder {
|
||||
let authenticated_client = config::try_authenticate_client(&shared.cfg.clients, &qs.token);
|
||||
|
||||
|
|
Loading…
Reference in a new issue