reqwest example combined with cli tutorial
This commit is contained in:
parent
6d3537c084
commit
c4abe1277f
@ -11,7 +11,8 @@ I actually never did this properly. currently reading [this guide](https://clig.
|
||||
## Existential crisis
|
||||
* ideally a tool on your machine should be easy to install
|
||||
* python versions, venvs etc feels more like a problem here than in a web application
|
||||
* attempt to write something in go?
|
||||
* attempt to write something in rust?
|
||||
* currently following some rust tutorials
|
||||
|
||||
## Readme driven development
|
||||
* have crunk-scheduler do all the conversion to html in rss.
|
||||
@ -19,3 +20,4 @@ I actually never did this properly. currently reading [this guide](https://clig.
|
||||
- post a simple text
|
||||
- post markdown or html snippets
|
||||
- post files
|
||||
* be able to set a time when something is scheduled.
|
||||
|
28
src/main.rs
28
src/main.rs
@ -1,3 +1,5 @@
|
||||
#![deny(warnings)]
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
/// Search for a pattern in a file and display the lines that contain it.
|
||||
@ -5,18 +7,24 @@ use clap::Parser;
|
||||
|
||||
struct Cli {
|
||||
url: String,
|
||||
path: std::path::PathBuf,
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// This is using the `tokio` runtime. You'll need the following dependency:
|
||||
//
|
||||
// `tokio = { version = "1", features = ["full"] }`
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), reqwest::Error> {
|
||||
// Some simple CLI args requirements...
|
||||
let args = Cli::parse();
|
||||
let result = std::fs::read_to_string(&args.path);
|
||||
let content = match result {
|
||||
Ok(content) => content,
|
||||
Err(error) => {
|
||||
return Err(error.into());
|
||||
}
|
||||
};
|
||||
println!("file content: {}", content);
|
||||
let url = args.url;
|
||||
|
||||
eprintln!("Fetching {:?}...", url);
|
||||
let res = reqwest::get(url).await?;
|
||||
|
||||
eprintln!("Response: {:?} {}", res.version(), res.status());
|
||||
eprintln!("Headers: {:#?}\n", res.headers());
|
||||
let body = res.text().await?;
|
||||
println!("{}", body);
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user