feat: v0.2.5, support go scripts

This commit is contained in:
2024-12-29 17:13:41 +08:00
parent affcb233bd
commit 3ace53b509
11 changed files with 163 additions and 31 deletions

32
src/script.template.rs Normal file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env runrs
//! ```cargo
//! [dependencies]
//! serde = { version = "1.0", features = ["derive"] }
//! serde_json = "1.0"
//! reqwest = { version = "0.11", features = ["blocking", "json"] }
//! rust_util = { version = "0.6" }
//! ```
use rust_util::{failure_and_exit, success};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
struct IpResponse {
status: u16,
message: String,
ip: String,
#[serde(rename = "userAgent")]
user_agent: Option<String>,
}
const GET_IP_URL: &'static str = "https://hatter.ink/ip/ip.jsonp";
fn main() {
let ip_response: IpResponse = reqwest::blocking::get(GET_IP_URL).unwrap_or_else(|e| {
failure_and_exit!("Send request to: {} failed: {}", GET_IP_URL, e);
}).json().unwrap_or_else(|e| {
failure_and_exit!("Parse response from: {}, failed: {}", GET_IP_URL, e);
});
success!("Your IP address is: {}", ip_response.ip);
}