rdiaz82 commented on a change in pull request #1: Proposed changes to 
action_loop
URL: 
https://github.com/apache/incubator-openwhisk-runtime-rust/pull/1#discussion_r263592618
 
 

 ##########
 File path: rust1.32/src/action_loop/src/main.rs
 ##########
 @@ -1,49 +1,46 @@
-extern crate serde_json;
-extern crate actions;
-extern crate libc;
-
-use std::env;
-use std::io::{self, Write, stdout, stderr};
-use std::fs::File;
-use std::os::unix::io::FromRawFd;
-use std::collections::HashMap;
-use serde_json::{Value, Error};
 use actions::main as actionMain;
 
+use serde_derive::Deserialize;
+use serde_json::{Error, Value};
+use std::{
+    collections::HashMap,
+    env,
+    fs::File,
+    io::{stderr, stdin, stdout, BufRead, Write},
+    os::unix::io::FromRawFd,
+};
+
+#[derive(Debug, Clone, PartialEq, Deserialize)]
+struct Input {
+    value: HashMap<String, Value>,
+    #[serde(flatten)]
+    environment: HashMap<String, Value>,
+}
+
 fn main() {
-    let mut fd3 = unsafe { File::from_raw_fd(3)};
-    loop {
-        let mut buffer = String::new();
-        io::stdin().read_line(&mut buffer).unwrap();
-        let parsed_input:Result<HashMap<String,Value>,Error> = 
serde_json::from_str(&buffer);
-        let mut payload:HashMap<String, Value> = HashMap::new();
+    let mut fd3 = unsafe { File::from_raw_fd(3) };
+    let stdin = stdin();
+    for line in stdin.lock().lines() {
+        let buffer: String = line.expect("Error reading line");
+        let parsed_input: Result<Input, Error> = serde_json::from_str(&buffer);
         match parsed_input {
-            Ok(n) => {
-                for (key, val) in n {
-                    if key == "value" {
-                        let mut 
unparsed_payload:Result<HashMap<String,Value>,Error> = 
serde_json::from_value(val);
-                        match unparsed_payload {
-                            Ok(value) => payload = value,
-                            Err(err) => {
-                                eprintln!("Error parsing value json: {}", err);
-                                continue
-                            }
-                        }
-                    } else {
-                        env::set_var(format!("__OW_{}", key.to_uppercase()), 
val.to_string());
+            Ok(input) => {
+                for (key, val) in input.environment {
 
 Review comment:
   yeah! this is just a personal style suggestion, feel free to ignore it 😄 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to