-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.rs
38 lines (35 loc) · 925 Bytes
/
build.rs
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
use dotenv::dotenv;
use std::env;
use std::io::Write;
fn write_link_info_type(file: &mut std::fs::File) -> Result<(), std::io::Error> {
let cid = env::var("GOOGLE_CLIENT_ID").unwrap();
let cls = env::var("GOOGLE_CLIENT_SECRET").unwrap();
let data = format!(
"pub struct Secrets {{
pub client_id: String,
pub client_secret: String,
}}
impl Secrets {{
pub fn new() -> Secrets {{
Secrets {{
client_id: \"{}\".to_string(),
client_secret: \"{}\".to_string(),
}}
}}
}}",
cid, cls
);
file.write_all(data.as_bytes())?;
Ok(())
}
fn generate_module() -> Result<(), std::io::Error> {
let mut module = std::fs::File::create(format!("src/{}.rs", "secrets"))?;
write_link_info_type(&mut module)?;
Ok(())
}
fn main() {
dotenv().ok();
if let Err(e) = generate_module() {
eprintln!("Error: {}", e);
}
}