1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! This is documentation for the `awf-help` crate.
//!
//! # Examples
//! Cargo.toml add
//! ```
//! [dependencies]
//! awf-help = "0.1"
//! actix-web = "1.0"
//! inventory = "0.1"
//! ```
//! import namespace
//! ```
//! extern crate awf_help;
//! use awf_help::{config, route,route_res, ServiceFactory};
//! ```
//! config webservice
//! ```
//!     HttpServer::new(|| App::new().configure(config))
//!         .bind("127.0.0.1:8000")
//!         .expect("Can not bind to port 8000")
//!         .run()
//!         .unwrap();
//!  ```
//! add decorator
//!  ```
//! #[route(GET, "/")]
//! fn greet(req: HttpRequest) -> String {
//!    let name = req.match_info().get("name").unwrap_or("World");
//!    format!("Hello {}!", &name)
//! }
//!  #[route(POST, "/")]
//!  #[route(HEAD, "/")]
//!  ```
//! 
//!  ```
//! #[route_res("/hello")]
//! impl Hello {
//!     fn get(req: HttpRequest) -> String {
//!         format!("get Hello !")
//!     }
//!     fn post(req: HttpRequest) -> String {
//!         format!("post Hello !")
//!     }
//! }
//!  ```
//!
use actix_web::web;
pub trait ServiceFactory {
    fn register(&self, config: &mut web::ServiceConfig);
}

inventory::collect!(Box<dyn ServiceFactory>);
pub fn config(cfg: &mut web::ServiceConfig) {
    for route in inventory::iter::<Box<dyn ServiceFactory>> {
        route.register(cfg);
    }
}
extern crate awf_codegen;
pub use awf_codegen::route;
pub use awf_codegen::route_res;