1#![warn(rust_2018_idioms)]
2#![forbid(unsafe_code)]
3
4#[macro_use]
5extern crate slog_scope;
6
7mod auth;
8mod error;
9mod extractors;
10mod headers;
11mod metrics;
12mod routers;
13mod routes;
14mod server;
15mod settings;
16
17use docopt::Docopt;
18use serde::Deserialize;
19use std::error::Error;
20
21use autopush_common::logging;
22
23const USAGE: &str = "
24Usage: autoendpoint [options]
25
26Options:
27 -h, --help Show this message
28 --config=CONFIGFILE AutoEndpoint configuration file path.
29";
30
31#[derive(Debug, Deserialize)]
32struct Args {
33 flag_config: Option<String>,
34}
35
36#[actix_rt::main]
37async fn main() -> Result<(), Box<dyn Error>> {
38 let args: Args = Docopt::new(USAGE)
39 .and_then(|d| d.deserialize())
40 .unwrap_or_else(|e| e.exit());
41 let settings = settings::Settings::with_env_and_config_file(&args.flag_config)?;
42 let host_port = format!("{}:{}", &settings.host, &settings.port);
43 logging::init_logging(
44 !settings.human_logs,
45 env!("CARGO_PKG_NAME"),
46 env!("CARGO_PKG_VERSION"),
47 )
48 .expect("Logging failed to initialize");
49 debug!("Starting up autoendpoint...");
50
51 let _sentry = sentry::init(sentry::ClientOptions {
52 release: sentry::release_name!(),
53 attach_stacktrace: true,
54 ..autopush_common::sentry::client_options()
55 });
56
57 let server = server::Server::with_settings(settings)
59 .await
60 .expect("Could not start server");
61 info!(
62 "Starting autoendpoint on port: {} ({})",
63 host_port,
64 logging::parallelism_banner()
65 );
66 server.await?;
67
68 info!("Shutting down autoendpoint");
70 logging::reset_logging();
71 Ok(())
72}