chore: reorg

This commit is contained in:
2020-10-17 11:47:07 +08:00
parent 9d4d830115
commit a034988643
56 changed files with 13431 additions and 0 deletions

1087
__web/reqwest/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

13
__web/reqwest/Cargo.toml Normal file
View File

@@ -0,0 +1,13 @@
[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]
async-trait = "0.1.30"
tokio = { version = "0.2.6", features = ["full"] }
reqwest = "0.10.4"

63
__web/reqwest/src/main.rs Normal file
View File

@@ -0,0 +1,63 @@
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<_, Box<dyn Call>> = HashMap::new();
map.insert("1", Box::new(T001{}) );
map.insert("2", Box::new(T002{}) );
let c = match map.get(a.as_str()) {
Some(c) => c, None => {
println!("[ERROR] Cannot find {}", a);
return;
},
};
match c.call().await {
Ok(_) => println!("[OK] Call fn ok: {}", a),
Err(err) => println!("[ERROR] Call fn error: {}, message: {}", a, err),
}
}
#[async_trait::async_trait]
trait Call {
async fn call(&self) -> Result<(), Box<dyn std::error::Error>>;
}
struct T001();
#[async_trait::async_trait]
impl Call for T001 {
async fn call(&self) -> Result<(), Box<dyn std::error::Error>> {
let ip = reqwest::get("https://hatter.ink/ip/ip.jsonp").await?.text().await?;
println!("{}", ip);
Ok(())
}
}
struct T002();
#[async_trait::async_trait]
impl Call for T002 {
async fn call(&self) -> Result<(), Box<dyn std::error::Error>> {
// let resp = reqwest::get("https://hatter.ink/ip/ip.jsonp").await?;
// use std::io::Read;
// let mut buff = [0_u8; 1024];
// loop {
// match resp.read(buff) {
// Ok(_) => (),
// Err(_) => (),
// }
// }
println!("Hello World 2");
Ok(())
}
}