[][src]Macro cgi::cgi_try_main

macro_rules! cgi_try_main {
    ( $func:expr ) => { ... };
}

Create a CGI main function based on a function which returns a Result<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 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))
} }