gui prints output from an http get to a configured URL

This commit is contained in:
bel
2023-03-25 09:59:39 -06:00
parent 8182f90783
commit b1cb419f3d
5 changed files with 516 additions and 5 deletions

View File

@@ -41,6 +41,12 @@ pub struct GUI {
pub release: PreSufFix,
pub format: Option<String>,
pub user: String,
pub feedback: GUIFeedback,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GUIFeedback {
pub url: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
@@ -138,6 +144,12 @@ fn build_config_std() -> Config {
false => None,
},
},
feedback: GUIFeedback{
url: match env::var("INPUT_GUI_FEEDBACK_URL") {
Ok(url) => Some(url),
Err(_) => None,
},
},
}),
device: None,
udp: Some(UDP{

View File

@@ -8,9 +8,10 @@ use handlebars::Handlebars;
use serde_json::json;
use std::time::{SystemTime, UNIX_EPOCH};
use std::thread;
use reqwest;
use crate::stream::OutputStream;
use crate::config::GUI;
use crate::config::{GUI,GUIFeedback};
pub fn main(cfg: GUI, output_stream: Box<dyn OutputStream>) -> iced::Result {
let def: iced::Settings<()> = Settings::default();
@@ -186,9 +187,11 @@ impl Application for Main {
fn new(flags: Self::Flags) -> (Self, Command<Message>) {
let (sender, receiver) = std::sync::mpsc::channel();
let feedback_cfg = flags.cfg.feedback.clone();
thread::spawn(move || {
Feedback{
c: sender,
cfg: feedback_cfg,
}.listen()
});
return (Self {
@@ -330,6 +333,7 @@ impl Application for Main {
struct Feedback {
c: std::sync::mpsc::Sender<String>,
cfg: GUIFeedback,
}
impl Feedback {
@@ -344,7 +348,16 @@ impl Feedback {
}
fn read(&mut self) -> Option<String> {
return Some(String::from(format!("feedback.read: {:?}", SystemTime::now())));
return match &self.cfg.url {
Some(url) => match reqwest::blocking::get(url) {
Ok(resp) => match resp.text() {
Ok(text) => Some(text),
_ => None,
},
_ => None,
},
_ => None,
};
}
fn write(&mut self, msg: String) {

15
src/testdata/http.go vendored Normal file
View File

@@ -0,0 +1,15 @@
package main
import (
"net/http"
"os"
)
func main() {
p := os.Getenv("PORT")
if err := http.ListenAndServe(":"+p, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(os.Getenv("BODY")))
})); err != nil {
panic(err)
}
}