
AthenaEngine
Web server engine for rust
External library
[dependencies]
chrono = "0.4.23"
urlencoding = "2.1.2"
How to use?
use std::collections::HashMap;
use AthenaEngine::server;
use AthenaEngine::server::page_manager::page_manager;
use AthenaEngine::server::page_manager::page_manager::PageInfo;
use AthenaEngine::server::response_parser::response_parser::{default_response_writer, IsResponseDataCreateSuccess, Response, ResponseCookies};
fn main() {
let mut all_page_list: HashMap<String, PageInfo> = HashMap::new();
let hello_page_info : PageInfo = PageInfo {
file_path: "A:\\AthenaEngine\\Rust\\hello.html".to_string(), is_access: true };
all_page_list.insert(String::from("/hello.html"), hello_page_info);
unsafe {
page_manager::ALL_PAGES.pages = Some(all_page_list);
}
unsafe {
server::EVENT.event_request = Some(Box::new(|request| {
}));
server::EVENT.event_response = Some(Box::new(|request| {
let mut cookies_list : Vec<ResponseCookies> = Vec::new();
let cookie : ResponseCookies = ResponseCookies {
name: "test-my-cookie".to_string(),
value: "test-my-cookie-value".to_string(),
path: "/".to_string(),
};
cookies_list.push(cookie);
let response : Response = default_response_writer(&request, Some(cookies_list), None);
if response.is_success == IsResponseDataCreateSuccess::SUCCESS {
match &response.headers {
None => {}
Some(value) => {
println!("{:?}", value);
}
}
}
return response;
}));
}
server::start_server(String::from("127.0.0.1"), 4444);
}
Expansion module description
server::page_manager::page_template_parser (function)
You can invoke body structure and template functions. You can also use an external template engine template engine without using this feature.
WARNING! This grammar is not perfect. The programmer may not behave as intended.
This grammar requires open (\r\n) characters and should not be indented (Tab) when using dedicated grammar.
< Grammar >
Variable notation: <#>var.(Variable name)
Recurring statement notation: <#>control.for (start num),(end num)
Repeating statement termination notation: <#>control.for_end
< Rust file >
server::EVENT.event_response = Some(Box::new(|request| {
let mut response : Response = default_response_writer(&request, None, None);
match &response.body {
None => {}
Some(response_body) => {
match &response_body.body_str {
None => {}
Some(html) => { let mut var : HashMap<String, GetPageTemplateVar> = HashMap::new();
var.insert(String::from("variable_1"), Box::new(|| {
return String::from("Hello my var!");
}));
let change_body : String = page_template_parser(html.clone(), var);
let change_body_len : String = change_body.clone().len().to_string();
let response_body : ResponseBody = ResponseBody {
body_str: Some(change_body),
};
let mut header : Option<HashMap<String, String>> = response.headers;
let mut header_new : HashMap<String, String>;
match header {
None => {
header_new = HashMap::new();
}
Some(header) => {
header_new = header;
header_new.insert("Content-Length".to_string(), change_body_len);
}
}
let mut new_response : Response = Response {
is_success: response.is_success,
response_code: response.response_code,
http_version: response.http_version,
headers: Some(header_new),
cookies: response.cookies,
body: Some(response_body),
};
return new_response;
}
}
}
}
return response;
}));
< HTML file >
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<#>var.variable_1
</br>
<#>control.for 0,10
print 1 -- 10 </br>
<#>control.for_end
</body>
</html>
log::log_writer, log::log_more_text_writer (function)
The dedicated Log Output Manager lets you print logs beautifully.
println!("{}", log_text_writer(error.to_string(), String::from("Log Generating entity"), LogTypeTag::WARNING));
println!("{}", log_more_text_writer(error.to_string(), String::from("Log Generating entity"), LogTypeTag::WARNING), String::from("More text"));
License
MIT License
Copyright (c) 2022 CHOI SI-HUN
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.