Skip to content

Commit b966cc5

Browse files
committed
Inject category toml string
1 parent 1da15a6 commit b966cc5

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/bin/server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ fn main() {
117117
let app = cargo_registry::App::new(&config);
118118
let app = cargo_registry::middleware(Arc::new(app));
119119

120-
cargo_registry::categories::sync().unwrap();
120+
let categories_toml = include_str!("../categories.toml");
121+
cargo_registry::categories::sync(&categories_toml).unwrap();
121122

122123
let port = if heroku {
123124
8888

src/categories.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,14 @@ struct NewCategory {
9898
description: String,
9999
}
100100

101-
pub fn sync() -> CargoResult<()> {
101+
pub fn sync(toml_str: &str) -> CargoResult<()> {
102102
use diesel::pg::upsert::*;
103103
use diesel::expression::dsl::all;
104104

105105
let conn = db::connect_now().unwrap();
106106

107-
let categories = include_str!("./categories.toml");
108107
let toml: toml::value::Table =
109-
toml::from_str(categories).expect("Could not parse categories.toml");
108+
toml::from_str(toml_str).expect("Could not parse categories toml");
110109

111110
let categories = categories_from_toml(&toml, None)
112111
.expect("Could not convert categories from TOML")

0 commit comments

Comments
 (0)