+9
-7
smart-modules/contruct-post-uri/src/lib.rs
+9
-7
smart-modules/contruct-post-uri/src/lib.rs
···
1
1
use eyre::eyre;
2
2
use fluvio_smartmodule::{RecordData, Result, SmartModuleRecord, smartmodule};
3
3
use serde_json::{Map, Value};
4
-
use std::str::FromStr;
5
4
6
-
#[smartmodule(map)]
7
-
pub fn map(record: &SmartModuleRecord) -> Result<(Option<RecordData>, RecordData)> {
5
+
#[smartmodule(filter_map)]
6
+
pub fn filter_map(record: &SmartModuleRecord) -> Result<Option<(Option<RecordData>, RecordData)>> {
8
7
let key = record.key.clone();
9
8
10
9
let string = std::str::from_utf8(record.value.as_ref())?;
···
13
12
.as_object_mut()
14
13
.ok_or(eyre!("Failed to parse value"))?;
15
14
16
-
let uri = get_uri(obj)?;
17
-
let uri_value = Value::String(uri);
18
-
obj.insert("uri".to_string(), uri_value);
15
+
if let Ok(uri) = get_uri(obj) {
16
+
let uri_value = Value::String(uri);
17
+
obj.insert("uri".to_string(), uri_value);
19
18
20
-
Ok((key, value.to_string().as_str().into()))
19
+
Ok(Some((key, value.to_string().as_str().into())))
20
+
} else {
21
+
Ok(None)
22
+
}
21
23
}
22
24
23
25
fn get_uri(obj: &Map<String, Value>) -> Result<String> {