add reqwest

This commit is contained in:
2020-05-03 12:50:43 +08:00
parent d6df92636b
commit 609d89ee4e
3 changed files with 1119 additions and 0 deletions

1075
reqwest/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

12
reqwest/Cargo.toml Normal file
View File

@@ -0,0 +1,12 @@
[package]
name = "reqwest"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "0.2.6", features = ["full"] }
reqwest = "0.10.4"

32
reqwest/src/main.rs Normal file
View 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(())
}