add reqwest
This commit is contained in:
1075
reqwest/Cargo.lock
generated
Normal file
1075
reqwest/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
reqwest/Cargo.toml
Normal file
12
reqwest/Cargo.toml
Normal 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
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