initial commit
This commit is contained in:
commit
f79b9992bc
|
@ -0,0 +1,4 @@
|
|||
CR_DATABASE="mysql://localhost/cipher_relay"
|
||||
|
||||
# This is only for sqlx compile time checks
|
||||
DATABASE_URL="mysql://localhost/cipher_relay"
|
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
.idea
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "cipher-relay"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["antifallobst"]
|
||||
license = "MIT"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.81"
|
||||
log = "0.4.21"
|
||||
env_logger = "0.11.3"
|
||||
dotenv = "0.15.0"
|
||||
|
||||
actix-web = "4.5.1"
|
||||
sqlx = { version = "0.7.4", features = ["runtime-tokio", "tls-native-tls"] }
|
|
@ -0,0 +1,20 @@
|
|||
Copyright 2023 antifallobst <antifallobst@systemausfall.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the “Software”), to deal in
|
||||
the Software without restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,33 @@
|
|||
use anyhow::{bail, Result};
|
||||
use log::info;
|
||||
use std::env;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Config {
|
||||
addr: String,
|
||||
port: u16,
|
||||
database: String,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Loads the configuration from environment variables
|
||||
pub fn from_env() -> Result<Self> {
|
||||
Ok(Self {
|
||||
addr: env::var("CR_ADDRESS").unwrap_or_else(|_| {
|
||||
info!("Using default address 0.0.0.0");
|
||||
"0.0.0.0".to_string()
|
||||
}),
|
||||
port: match env::var("CR_PORT") {
|
||||
Ok(str) => match str.parse() {
|
||||
Ok(port) => port,
|
||||
Err(_) => bail!("Failed to parse environment variable CR_PORT: '{str}' is not a valid port number!"),
|
||||
},
|
||||
Err(_) => { info!("Using default port 42069"); 42069 }
|
||||
},
|
||||
database: match env::var("CR_DATABASE") {
|
||||
Ok(db) => db,
|
||||
Err(_) => bail!("The environment variable CR_DATABASE is required!"),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
mod config;
|
||||
|
||||
use anyhow::Result;
|
||||
use config::Config;
|
||||
use log::info;
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> Result<()> {
|
||||
dotenv::dotenv()?;
|
||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||
|
||||
info!("Starting Cipher Relay (v{} - )", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
let config = Config::from_env()?;
|
||||
|
||||
println!("{config:#?}");
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue