testando rust

This commit is contained in:
José Henrique Ivanchechen 2023-09-12 21:39:28 -03:00
parent 1dbd8c238f
commit cd1e9da710
6 changed files with 1379 additions and 0 deletions

5
.gitignore vendored
View File

@ -2,6 +2,11 @@
__pycache__ __pycache__
bin bin
obj obj
*.vscode
__pycache__
.idea
*/target
*.png *.png
*.csv *.csv

1266
ActixAPI/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

10
ActixAPI/Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "ActixAPI"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-web = "4"
actix-files = "0.6.2"

25
ActixAPI/Dockerfile Normal file
View File

@ -0,0 +1,25 @@
FROM rust:slim-bullseye AS build-env
WORKDIR /app
COPY . .
RUN apt update && apt install wget -y && \
wget https://files.ivanch.me/api/public/dl/Dj0gkp-m/small-image.png && \
wget https://files.ivanch.me/api/public/dl/FqHEPM1Q/big-image.png && \
wget https://files.ivanch.me/api/public/dl/nTAYqZwD/video.mp4 && \
mv small-image.png ./static && \
mv big-image.png ./static && \
mv video.mp4 ./static
RUN cargo build --release
FROM debian:bullseye-slim
WORKDIR /app
COPY --from=build-env /app/target/release .
COPY --from=build-env /app/static .
ENTRYPOINT ["./ActixAPI"]

40
ActixAPI/src/main.rs Normal file
View File

@ -0,0 +1,40 @@
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, HttpRequest, Result};
use actix_files::NamedFile;
use std::path::PathBuf;
#[get("/status/ok")]
async fn hello() -> impl Responder {
HttpResponse::Ok().body("{\"status\": 200}")
}
#[post("/echo")]
async fn echo(req_body: String) -> impl Responder {
HttpResponse::Ok().body(req_body)
}
async fn manual_hello() -> impl Responder {
HttpResponse::Ok().body("Hey there!")
}
async fn static_serve(req: HttpRequest) -> Result<NamedFile> {
let path: &str = req.path();
let real_path = &path[1..];
Ok(NamedFile::open(real_path)?)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
println!("Hello, world!");
HttpServer::new(|| {
App::new()
.route("/static/{filename:.*}", web::get().to(static_serve))
.service(hello)
.service(echo)
.route("/hey", web::get().to(manual_hello))
})
.bind(("0.0.0.0", 9090))?
.run()
.await
}

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html {
color-scheme: light dark;
}
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>
If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.
</p>
<p>
For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br />
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.
</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>