diff options
Diffstat (limited to 'src/bin/main.rs')
-rw-r--r-- | src/bin/main.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs index b07a524..ed9e179 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -31,6 +31,21 @@ fn create_user_prompt() -> Option<(String, String)> { Some((user.trim().to_string(), password)) } +fn create_admin_user(conn: &rusqlite::Connection) { + info!("Create admin user"); + if let Some((user, password)) = create_user_prompt() { + let enc = auth::encode("test_salt", password.as_str()); + systemhttp::db::insert_user( + &conn, user.as_str(), + &enc).expect("create user"); + } +} + +fn serve(context: systemhttp::server::Context, port: u16) { + let _server = systemhttp::server::serve(context, port).unwrap(); + println!("Serving on {}", port); +} + fn main() { let matches = App::new("systemhttpd") .version("0.1") @@ -62,24 +77,14 @@ fn main() { .expect(format!("opening sqlite database at {}", db_file).as_str()); systemhttp::db::init(&mut conn); - let mut serve = || { - let _server = systemhttp::server::serve(port).unwrap(); - println!("Serving on {}", port); - }; - - let mut create_admin_user = || { - info!("Create admin user"); - if let Some((user, password)) = create_user_prompt() { - let enc = auth::encode("test_salt", password.as_str()); - systemhttp::db::insert_user( - &mut conn, user.as_str(), - &enc).expect("create user"); - } + let mut context = systemhttp::server::Context { + base_url: "http://localhost:8080".to_string(), + conn: conn }; match matches.subcommand_name() { - Some("serve") => serve(), - Some("create_admin_user") => create_admin_user(), + Some("serve") => serve(context, port), + Some("create_admin_user") => create_admin_user(&context.conn), x => panic!("Don't know about subcommand: {:?}", x) } } |