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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#![feature(proc_macro_hygiene)]

extern crate bytes;
extern crate clap;
extern crate futures;
extern crate lazy_static;
extern crate maud;
extern crate mime;
extern crate mime_guess;
extern crate postgres;
extern crate serde;

extern crate actix_session;
extern crate actix_service;
extern crate actix_web;

extern crate slog;
extern crate slog_json;
extern crate slog_term;
extern crate slog_async;

#[macro_use]
extern crate rust_embed;

pub(crate) mod config {
  pub(crate) mod args;
  pub(crate) mod cfg;
}

pub(crate) mod models {
  pub(crate) mod field_type;
}

pub(crate) mod db {
  pub(crate) mod conn;
}

pub(crate) mod server {
  pub(crate) mod ctx;
  pub(crate) mod start;

  pub(crate) mod assets;
}

pub(crate) mod controllers {
  pub(crate) mod utils;

  pub(crate) mod error;
  pub(crate) mod static_file;

  pub(crate) mod home;
}

pub(crate) mod templates {
  pub(crate) mod components {
    pub(crate) mod header;
    pub(crate) mod header_noauth;
    pub(crate) mod navbar;
    pub(crate) mod page;
  }

  pub(crate) mod error;

  pub(crate) mod index;

  pub(crate) mod testbed;
}

use crate::config::cfg::AppConfig;

#[cfg(debug_assertions)]
fn is_debug() -> bool { true }

#[cfg(not(debug_assertions))]
fn is_debug() -> bool { false }

pub fn go() -> std::io::Result<()> {
  let matches = config::args::get_matches();
  let cfg_dir = match matches.value_of("config") {
    None => String::from("./tests/testbed"),
    Some(o) => String::from(o)
  };
  let verbose = matches.is_present("verbose") || is_debug();
  let port: i32 = match matches.value_of("port") {
    Some(p) => p.parse().unwrap(),
    None => 4200
  };
  let _e = "String".parse::<models::field_type::FieldType>();

  let cfg = AppConfig::new(cfg_dir, port, verbose);
  server::start::start(cfg)
}