sui_rust_operator/hookserver/
mod.rs

1mod state;
2
3use crate::hook::HookCaller;
4use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
5use state::HookData;
6
7#[get("/")]
8pub async fn hello() -> impl Responder {
9    HttpResponse::Ok().body("Hello world!")
10}
11
12#[post("/echo")]
13pub async fn echo(req_body: String) -> impl Responder {
14    HttpResponse::Ok().body(req_body)
15}
16
17pub async fn manual_hello() -> impl Responder {
18    HttpResponse::Ok().body("Hey there!")
19}
20
21#[get("/myinfo")]
22async fn share_info(data: web::Data<HookData>) -> impl Responder {
23    data.get_ref().to_string()
24}
25
26pub async fn start(bind_host: &str, port: u16, _hook: HookCaller) -> std::io::Result<()> {
27    HttpServer::new(|| {
28        App::new()
29            .app_data(web::Data::new(HookData::new("")))
30            .service(hello)
31            .service(echo)
32            .service(share_info)
33            .route("/hey", web::get().to(manual_hello))
34    })
35    .bind((bind_host, port))?
36    .run()
37    .await
38}