add reqwest
This commit is contained in:
32
reqwest/src/main.rs
Normal file
32
reqwest/src/main.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use std::env;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() {
|
||||
let a = match env::args().nth(1) {
|
||||
Some(a) => a, None => {
|
||||
println!("[ERROR] No args");
|
||||
return;
|
||||
},
|
||||
};
|
||||
let mut map = HashMap::new();
|
||||
map.insert("1", test001);
|
||||
|
||||
let f = match map.get(a.as_str()) {
|
||||
Some(f) => f, None => {
|
||||
println!("{}", &format!("[ERROR] Cannot find {}", a));
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
||||
match f().await {
|
||||
Ok(_) => println!("[OK] Call fn ok: {}", a),
|
||||
Err(err) => println!("[ERROR] Call fn error: {}, message: {}", a, err),
|
||||
}
|
||||
}
|
||||
|
||||
async fn test001() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let ip = reqwest::get("https://hatter.ink/ip/ip.jsonp").await?.text().await?;
|
||||
println!("{}", ip);
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user