Skip to content

Commit b63b767

Browse files
committed
hotfix: db is mandatory in config file
Fix a bug that panics if no db config is provided. now db config are optional
1 parent 3e0b41b commit b63b767

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/config_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl EndpointSearch for Vec<Endpoint> {
3737
#[derive(Serialize, Debug, Deserialize)]
3838
pub struct Config {
3939
pub endpoints: HashMap<String, Vec<Endpoint>>,
40-
pub db: Vec<DB>,
40+
pub db: Option<Vec<DB>>,
4141
}
4242

4343
impl Config {

src/main.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ fn main() {
3333
println!("Loaded {} {}", method, endpoint.path)
3434
}
3535
}
36-
for db in config.db {
37-
let dbh = db_handle::DbHandle::new(db.path, db.data);
38-
if dbh.is_err() {
39-
println!("Error loading db: {:?}", dbh.err());
40-
continue;
36+
if config.db.is_some() {
37+
let config_db = config.db.unwrap().clone();
38+
for db in config_db {
39+
let dbh = db_handle::DbHandle::new(db.path, db.data);
40+
if dbh.is_err() {
41+
println!("Error loading db: {:?}", dbh.err());
42+
continue;
43+
}
44+
let dbh = dbh.unwrap();
45+
println!("Loaded {} as db", dbh.root_path);
46+
dbs.push(dbh);
4147
}
42-
let dbh = dbh.unwrap();
43-
println!("Loaded {} as db", dbh.root_path);
44-
dbs.push(dbh);
4548
}
4649
let dbs: Arc<Mutex<Vec<DbHandle>>> = Arc::new(Mutex::new(dbs));
4750
let dbsc = dbs.clone();

0 commit comments

Comments
 (0)