Macro rust_cgi::cgi_try_main
source · macro_rules! cgi_try_main { ( $func:expr ) => { ... }; }
Expand description
Create a CGI main function based on a function which returns a Result<rust_cgi::Response, _>
If the inner function returns an Ok(...)
, that will be unwrapped & returned. If there’s an
error, it will be printed ({:?}
) to stderr (which apache doesn’t sent to the client, but
saves to a log file), and an empty HTTP 500 Server Error
response is sent instead.
Example
extern crate rust_cgi as cgi;
cgi::cgi_try_main! { |request: cgi::Request| -> Result<cgi::Response, String> {
let f = std::fs::read_to_string("greeting.txt").map_err(|_| "Couldn't open file")?;
Ok(cgi::text_response(200, f))
} }