-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mise en place config et basique home
- Loading branch information
Showing
8 changed files
with
153 additions
and
2 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
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,84 @@ | ||
use std::path::PathBuf; | ||
|
||
use dotenvy::dotenv; | ||
use serde::Deserialize; | ||
use tool_tracing::tracing_kind::Tracing; | ||
use tracing::info; | ||
|
||
const API_PORT: &str = "API_PORT"; | ||
const CONTENT_PATH: &str = "CONTENT_PATH"; | ||
|
||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct Config { | ||
pub port: u16, | ||
pub content_path: String, | ||
pub tracing: Vec<Tracing>, | ||
} | ||
|
||
fn override_config_with_env(config: Config) -> Config { | ||
let mut config = config; | ||
if let Ok(port) = std::env::var(API_PORT) { | ||
if let Ok(port) = port.parse::<u16>() { | ||
config.port = port; | ||
} | ||
} | ||
if let Ok(content_path) = std::env::var(CONTENT_PATH) { | ||
config.content_path = content_path; | ||
} | ||
config | ||
} | ||
|
||
fn parse_config_from_file(path_buf: PathBuf) -> Config { | ||
let file = std::fs::File::open(path_buf).expect("file should open read only"); | ||
let reader = std::io::BufReader::new(file); | ||
serde_yaml::from_reader(reader).expect("file should be proper YAML") | ||
} | ||
|
||
pub fn parse_config(path_buf: PathBuf) -> Config { | ||
let config = parse_config_from_file(path_buf); | ||
override_config_with_env(config) | ||
} | ||
|
||
pub fn parse_local_config() -> Config { | ||
let mut path_buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
path_buf.push("../../content/config.yaml"); | ||
match dotenv() { | ||
Ok(_) => info!("Loaded .env file"), | ||
Err(err) => println!("No .env file found: {:?}", err), | ||
} | ||
parse_config(path_buf) | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub fn parse_test_config() -> Config { | ||
let mut path_buf = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
path_buf.push("../../test_dataset/content/config.yaml"); | ||
println!("{:?}", path_buf); | ||
parse_config(path_buf) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::env; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_parse_config() { | ||
let config = parse_test_config(); | ||
assert_eq!(config.port, 5437); | ||
assert_eq!(config.content_path, "./content"); | ||
let config = Config { | ||
port: 8080, | ||
content_path: "content".to_string(), | ||
tracing: vec![], | ||
}; | ||
env::set_var(API_PORT, "8081"); | ||
env::set_var(CONTENT_PATH, "content2"); | ||
let config = override_config_with_env(config); | ||
assert_eq!(config.port, 8081); | ||
assert_eq!(config.content_path, "content2"); | ||
let _local = parse_local_config(); | ||
assert!(true); | ||
} | ||
} |
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 +1,2 @@ | ||
pub mod config; | ||
pub mod homeprofil; |
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,6 @@ | ||
port: 5437 | ||
content_path: "./content" | ||
tracing: | ||
- name: "console" | ||
level: 2 | ||
kind: "Console" |
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
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,6 @@ | ||
port: 5437 | ||
content_path: "./content" | ||
tracing: | ||
- name: "console" | ||
level: 2 | ||
kind: "Console" |
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,52 @@ | ||
name: Maxime Leriche | ||
presentation: | | ||
Hello, Moi c'est Maxime, je suis un développeur passionné autant par les nouvelles technologies qu'un nouveau projet. | ||
J'aime apprendre en permanence et construire ce que j'estime étre ma base de connaissance. | ||
Et vous êtes ici sur mon site qui est un savant mélange de mes passions et de mes projets. | ||
Alors, bienvenue et bonne visite ! | ||
coverTitle: | ||
- Développeur | ||
- Passionné | ||
- Ops | ||
- Back | ||
- Front | ||
- Kube and Co | ||
- Architecture | ||
- Too much coffee | ||
- And lot's more | ||
cvUrl: /media/cv.pdf | ||
url: | ||
- name: LinkedIn | ||
url: https://www.linkedin.com/in/maxime-leriche/ | ||
primaire: true | ||
imgUrl: /media/linkedin.png | ||
- name: GitHub | ||
url: https://github.com/batleforc | ||
primaire: true | ||
imgUrl: /media/github.png | ||
- name: Git Weebo | ||
url: https://git.weebo.fr/batleforc | ||
primaire: true | ||
imgUrl: /media/gitea.png | ||
history: | ||
- title: Bac STI2D | ||
lieux: Lycée Marie Curie, Nogent sur Oise | ||
date: 2015 - 2018 | ||
weight: 1 | ||
imgUrl: /media/lycee_marie_curie.jpg | ||
description: | | ||
Bac STI2D option ITEC (Innovation Technologique et Eco-Conception) | ||
Obtenu avec mention Bien | ||
Découverte de la la conception de piéce en 3D et de l'annalyse des contraintes mécaniques | ||
Base importante pour ma passion pour l'impression 3D et la conception de piéce | ||
- title: DUT INFO | ||
lieux: IUT Amiens, Amiens | ||
date: 2018 - 2020 | ||
weight: 2 | ||
imgUrl: /media/iut_amiens.jpg | ||
url: | ||
- name: Objectif CIAP | ||
url: https://www.youtube.com/watch?v=fZ8DYxclVvQ | ||
description: | | ||
DUT Informatique | ||
Découverte de la programmation et des bases nécessaires pour devenir développeur (Java, C, SQL, C#, JS, Python, PHP, etc) |