init
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
1152
Cargo.lock
generated
Normal file
1152
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "zoidberg"
|
||||
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"
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
3
src/bin/hello.rs
Normal file
3
src/bin/hello.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("hello");
|
||||
}
|
||||
42
src/main.rs
Normal file
42
src/main.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, Result};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Update {
|
||||
id: i64,
|
||||
status: String,
|
||||
}
|
||||
|
||||
#[get("/register")]
|
||||
async fn register() -> impl Responder {
|
||||
HttpResponse::Ok().body("Worker node registered")
|
||||
}
|
||||
|
||||
#[get("/fetch")]
|
||||
async fn fetch() -> impl Responder {
|
||||
HttpResponse::Ok().body("Here is some work")
|
||||
}
|
||||
|
||||
#[post("/update")]
|
||||
async fn update(u: web::Json<Update>) -> Result<String> {
|
||||
Ok(format!("Job {} updated with status {}", u.id, u.status))
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
async fn index() -> impl Responder {
|
||||
HttpResponse::Ok().body("Hello world!")
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.service(register)
|
||||
.service(fetch)
|
||||
.service(update)
|
||||
.service(index)
|
||||
})
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
Reference in New Issue
Block a user