GUI can now send to say as concat string

master
Bel LaPointe 2023-03-27 17:53:56 -06:00
parent 7e4b7b2080
commit 75149668ef
3 changed files with 25 additions and 10 deletions

View File

@ -45,7 +45,8 @@ pub struct GUI {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GUIFeedback {
pub url: Option<String>,
pub url_read: Option<String>,
pub url_say: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
@ -131,7 +132,11 @@ fn build_config_std() -> Config {
},
},
feedback: GUIFeedback{
url: match env::var("INPUT_GUI_FEEDBACK_URL") {
url_read: match env::var("INPUT_GUI_FEEDBACK_URL_READ") {
Ok(url) => Some(url),
Err(_) => None,
},
url_say: match env::var("INPUT_GUI_FEEDBACK_URL_SAY") {
Ok(url) => Some(url),
Err(_) => None,
},

View File

@ -407,19 +407,17 @@ impl Feedback {
},
_ => {},
};
/*
match self.read_from_client() {
Some(msg) if msg.len() > 0 => {
self.write_from_client(msg.clone());
},
_ => {},
};
*/
}
}
fn read_from_server(&mut self) -> Option<String> {
return match &self.cfg.url {
return match &self.cfg.url_read {
Some(url) => {
match reqwest::blocking::get(url) {
Ok(resp) => match resp.text() {
@ -443,19 +441,31 @@ impl Feedback {
};
}
/*
fn read_from_client(&mut self) -> Option<String> {
let last: Option<String> = None;
let mut last: Option<String> = None;
loop {
match self.recv_c.try_recv() {
Ok(msg) => {
last = msg;
last = Some(msg);
},
_ => break,
};
}
return last;
}
*/
fn write_from_client(&mut self, msg: String) {
match &self.cfg.url_say {
Some(url) => {
match reqwest::blocking::get(format!("{}{}", url, msg)) {
Err(err) => {
eprintln!("feedback.write_from_client: cannot say: {}", err);
},
_ => {},
};
},
_ => {},
};
}
}

View File

@ -11,7 +11,7 @@ func main() {
p := os.Getenv("PORT")
if err := http.ListenAndServe(":"+p, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, _ := io.ReadAll(r.Body)
log.Printf("> %s", b)
log.Printf("> %s (%+v) %s", r.URL, r.Header, b)
body := os.Getenv("BODY")
if body == "-" {
body = string(b)