1
0
mirror of https://github.com/actix/examples synced 2025-06-26 09:17:41 +02:00

restructure folders

This commit is contained in:
Rob Ede
2022-02-18 02:01:48 +00:00
parent 4d8573c3fe
commit cc3d356209
201 changed files with 52 additions and 49 deletions

8
unix-socket/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "unix-socket"
version = "1.0.0"
edition = "2021"
[dependencies]
env_logger = "0.9.0"
actix-web = "4.0.0-rc.1"

17
unix-socket/README.md Normal file
View File

@ -0,0 +1,17 @@
## Unix domain socket example
```bash
cd other/unix-socket
cargo run
# in another shell
curl --unix-socket /tmp/actix-uds.socket http://localhost/
Hello world!
```
Although this will only one thread for handling incoming connections
according to the [documentation](https://actix.github.io/actix-web/actix_web/struct.HttpServer.html#method.bind_uds).
And it does not delete the socket file (`/tmp/actix-uds.socket`) when stopping
the server, so it will fail to start next time you run it unless you delete
the socket file manually.

32
unix-socket/src/main.rs Normal file
View File

@ -0,0 +1,32 @@
use actix_web::{middleware, web, App, HttpRequest, HttpServer};
async fn index(_req: HttpRequest) -> &'static str {
"Hello world!"
}
#[actix_web::main]
#[cfg(unix)]
async fn main() -> std::io::Result<()> {
::std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
env_logger::init();
HttpServer::new(|| {
App::new()
// enable logger - always register Actix Web Logger middleware last
.wrap(middleware::Logger::default())
.service(
web::resource("/index.html")
.route(web::get().to(|| async { "Hello world!" })),
)
.service(web::resource("/").to(index))
})
.bind_uds("/tmp/actix-uds.socket")?
.run()
.await
}
#[cfg(not(unix))]
fn main() -> std::io::Result<()> {
println!("not supported");
Ok(())
}