Modify method of getting arguments
It may be inefficient, I dont know another way to do so easily.
This commit is contained in:
parent
680dc9d0fc
commit
88dfaed1a0
@ -17,7 +17,6 @@ use actix_web::{
|
|||||||
use crate::router::global;
|
use crate::router::global;
|
||||||
use json::JsonValue;
|
use json::JsonValue;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::sync::atomic::Ordering;
|
|
||||||
|
|
||||||
fn unhandled(req: HttpRequest, body: String) -> Option<JsonValue> {
|
fn unhandled(req: HttpRequest, body: String) -> Option<JsonValue> {
|
||||||
if body != String::new() {
|
if body != String::new() {
|
||||||
@ -215,12 +214,15 @@ pub struct Args {
|
|||||||
https: bool
|
https: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_args() -> Args {
|
||||||
|
Args::parse()
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
let args = Args::parse();
|
let args = get_args();
|
||||||
let port = args.port;
|
let port = args.port;
|
||||||
|
|
||||||
router::gree::HTTPS.store(args.https, Ordering::Relaxed);
|
|
||||||
let rv = HttpServer::new(|| App::new()
|
let rv = HttpServer::new(|| App::new()
|
||||||
.wrap_fn(|req, srv| {
|
.wrap_fn(|req, srv| {
|
||||||
println!("Request: {}", req.path());
|
println!("Request: {}", req.path());
|
||||||
|
@ -7,8 +7,6 @@ use json::{object, JsonValue};
|
|||||||
use hmac::{Hmac, Mac};
|
use hmac::{Hmac, Mac};
|
||||||
use rusqlite::params;
|
use rusqlite::params;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::sync::atomic::Ordering;
|
|
||||||
use std::sync::atomic::AtomicBool;
|
|
||||||
|
|
||||||
use openssl::pkey::PKey;
|
use openssl::pkey::PKey;
|
||||||
use openssl::rsa::Rsa;
|
use openssl::rsa::Rsa;
|
||||||
@ -333,12 +331,9 @@ pub fn migration_password_register(req: HttpRequest, body: String) -> HttpRespon
|
|||||||
send(req, resp)
|
send(req, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static!{
|
|
||||||
pub static ref HTTPS: AtomicBool = AtomicBool::new(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_protocol() -> String {
|
pub fn get_protocol() -> String {
|
||||||
if HTTPS.load(Ordering::SeqCst) == true {
|
let args = crate::get_args();
|
||||||
|
if args.https == true {
|
||||||
return String::from("https");
|
return String::from("https");
|
||||||
}
|
}
|
||||||
String::from("http")
|
String::from("http")
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use rusqlite::{Connection, params, ToSql};
|
use rusqlite::{Connection, params, ToSql};
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use json::{JsonValue, array};
|
use json::{JsonValue, array};
|
||||||
use clap::Parser;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use crate::router::clear_rate::Live;
|
use crate::router::clear_rate::Live;
|
||||||
@ -13,7 +12,7 @@ pub struct SQLite {
|
|||||||
|
|
||||||
impl SQLite {
|
impl SQLite {
|
||||||
pub fn new(path: &str, setup: fn(&SQLite)) -> SQLite {
|
pub fn new(path: &str, setup: fn(&SQLite)) -> SQLite {
|
||||||
let args = crate::Args::parse();
|
let args = crate::get_args();
|
||||||
fs::create_dir_all(&args.path).unwrap();
|
fs::create_dir_all(&args.path).unwrap();
|
||||||
let conn = Connection::open(format!("{}/{}", args.path, path)).unwrap();
|
let conn = Connection::open(format!("{}/{}", args.path, path)).unwrap();
|
||||||
conn.execute("PRAGMA foreign_keys = ON;", ()).unwrap();
|
conn.execute("PRAGMA foreign_keys = ON;", ()).unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user