-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add read_file function to return content file
Signed-off-by: Charley <[email protected]>
- Loading branch information
1 parent
a2c1137
commit efdc54a
Showing
4 changed files
with
37 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
language: rust | ||
env_path: .env | ||
code_path: src | ||
env_path: /home/charley/polytech/cloudlet/src/cli/config/example.env | ||
code_path: /home/charley/polytech/cloudlet/src/cli/src/main.rs | ||
log_level: debug |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HOST="localhost" | ||
PORT=3000 | ||
PASSWORD=3456 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
use crate::types::Config; | ||
use std::fs::File; | ||
use std::io::{self, Read}; | ||
use std::path::PathBuf; | ||
|
||
pub fn load_config(config_path: &str) -> io::Result<Config> { | ||
pub fn load_config(config_path: &PathBuf) -> io::Result<Config> { | ||
let mut file = File::open(config_path)?; | ||
let mut contents = String::new(); | ||
file.read_to_string(&mut contents)?; | ||
let config: Config = serde_yaml::from_str(&contents).unwrap(); | ||
let config: Config = serde_yaml::from_str(&contents) | ||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; | ||
Ok(config) | ||
} | ||
|
||
pub fn read_file(file_path: &str) -> io::Result<String> { | ||
let mut file = File::open(file_path)?; | ||
let mut contents = String::new(); | ||
file.read_to_string(&mut contents)?; | ||
Ok(contents) | ||
} |