Created
March 2, 2020 01:14
-
-
Save karno/77603bc7c863a9d7e4a09766a648a465 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub async fn load_or_init_api_key(token_file: &str) -> Result<ApiKey, ConfigError> { | |
let token_path = path::Path::new(token_file); | |
if token_path.exists() { | |
let token = ApiKey::load(token_path)?; | |
match ApiKey::load(token_path) { | |
Ok(token) => Ok(token), | |
Err(e) => { | |
eprintln!("failed to read application token file:"); | |
eprintln!("{}", e); | |
Err(e) | |
} | |
} | |
} else { | |
// create | |
println!("file not found -> create token file."); | |
let token = create_api_key().await?; | |
token.save(token_file)?; | |
Ok(token) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment