hyperlane-macros 0.1.5

hyperlane macro
Documentation

hyperlane-macros

Official Documentation

Api Docs

hyperlane macro.

Installation

To use this crate, you can run cmd:

cargo add hyperlane-macros

Use

use hyperlane::*;

#[hyperlane_macros::methods(get, post)]
async fn get_post(ctx: Context) {
    let _ = ctx.set_response_body("get_post").await.send().await;
}

#[hyperlane_macros::get]
async fn get(ctx: Context) {
    let _ = ctx.set_response_body("get").await.send().await;
}

#[hyperlane_macros::post]
async fn post(ctx: Context) {
    let _ = ctx.set_response_body("post").await.send().await;
}

#[hyperlane_macros::connect]
async fn connect(ctx: Context) {
    let _ = ctx.set_response_body("connect").await.send().await;
}

#[hyperlane_macros::delete]
async fn delete(ctx: Context) {
    let _ = ctx.set_response_body("delete").await.send().await;
}

#[hyperlane_macros::head]
async fn head(ctx: Context) {
    let _ = ctx.set_response_body("head").await.send().await;
}

#[hyperlane_macros::options]
async fn options(ctx: Context) {
    let _ = ctx.set_response_body("options").await.send().await;
}

#[hyperlane_macros::patch]
async fn patch(ctx: Context) {
    let _ = ctx.set_response_body("patch").await.send().await;
}

#[hyperlane_macros::put]
async fn put(ctx: Context) {
    let _ = ctx.set_response_body("put").await.send().await;
}

#[hyperlane_macros::trace]
async fn trace(ctx: Context) {
    let _ = ctx.set_response_body("trace").await.send().await;
}

fn error_handler(error: String) {
    eprintln!("{}", error);
    let _ = std::io::Write::flush(&mut std::io::stderr());
}

#[tokio::main]
async fn main() {
    let server: Server = Server::new();
    server.host("0.0.0.0").await;
    server.port(60000).await;
    server.error_handler(error_handler).await;
    server.route("/get_post", get_post).await;
    server.route("/get", get).await;
    server.route("/post", post).await;
    server.route("/connect", connect).await;
    server.route("/delete", delete).await;
    server.route("/head", head).await;
    server.route("/options", options).await;
    server.route("/patch", patch).await;
    server.route("/put", put).await;
    server.route("/trace", trace).await;
    let test = || async move {
        server.run().await.unwrap();
    };
    let _ = tokio::time::timeout(std::time::Duration::from_secs(60), test()).await;
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Contact

For any inquiries, please reach out to the author at root@ltpp.vip.