feat: add alibaba cloud fn template
This commit is contained in:
39
{{project_name}}/src/main.rs
Normal file
39
{{project_name}}/src/main.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use std::convert::Infallible;
|
||||
use hyper::service;
|
||||
use hyper::{Body, Request, Response, Server};
|
||||
|
||||
async fn hello(request: Request<Body>) -> Result<Response<Body>, Infallible> {
|
||||
let mut buff = String::with_capacity(1024);
|
||||
buff.push_str(&request.method().to_string());
|
||||
buff.push(' ');
|
||||
buff.push_str(&request.uri().to_string());
|
||||
buff.push(' ');
|
||||
buff.push_str(&format!("{:?}", request.version().to_owned()));
|
||||
buff.push('\n');
|
||||
for header in request.headers() {
|
||||
buff.push_str(&header.0.to_string());
|
||||
buff.push_str(": ");
|
||||
let val = header.1.to_str().unwrap_or_else(|_| "<to_string_error>");
|
||||
if header.0.to_string().contains("access-key-secret") && !val.is_empty() {
|
||||
buff.push_str("******");
|
||||
} else {
|
||||
buff.push_str(val);
|
||||
}
|
||||
buff.push('\n');
|
||||
}
|
||||
Ok(Response::new(Body::from(buff)))
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let make_svc = service::make_service_fn(|_conn| {
|
||||
async { Ok::<_, Infallible>(service::service_fn(hello)) }
|
||||
});
|
||||
|
||||
let addr = ([0, 0, 0, 0], 9000).into();
|
||||
let server = Server::bind(&addr).serve(make_svc);
|
||||
println!("Listening on http://{}", addr);
|
||||
|
||||
server.await?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user