Fix conditional compilaton
This commit is contained in:
parent
49dab174cc
commit
458c651cd4
3 changed files with 58 additions and 28 deletions
|
|
@ -10,33 +10,41 @@ use std::sync::Arc;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
use sqlx::postgres::PgPool;
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "datastore")] {
|
||||||
|
use sqlx::postgres::PgPool;
|
||||||
|
}
|
||||||
|
}
|
||||||
use log::error;
|
use log::error;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::string::ToString;
|
use std::string::ToString;
|
||||||
|
use cfg_if::cfg_if;
|
||||||
use crate::reggie::UnitPacketRead;
|
use crate::reggie::UnitPacketRead;
|
||||||
|
|
||||||
const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip";
|
const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip";
|
||||||
|
|
||||||
pub static RNEX_DATASTORE_DATABASE_URL: LazyLock<String> = LazyLock::new(|| {
|
cfg_if! {
|
||||||
std::env::var("RNEX_DATASTORE_DATABASE_URL")
|
if #[cfg(feature = "datastore")] {
|
||||||
.expect("RNEX_DATASTORE_DATABASE_URL must be set")
|
pub static RNEX_DATASTORE_DATABASE_URL: LazyLock<String> = LazyLock::new(|| {
|
||||||
});
|
std::env::var("RNEX_DATASTORE_DATABASE_URL")
|
||||||
|
.expect("RNEX_DATASTORE_DATABASE_URL must be set")
|
||||||
|
});
|
||||||
|
|
||||||
pub static DB_POOL: OnceLock<PgPool> = OnceLock::new();
|
pub static DB_POOL: OnceLock<PgPool> = OnceLock::new();
|
||||||
|
|
||||||
pub fn get_db() -> &'static PgPool {
|
pub fn get_db() -> &'static PgPool {
|
||||||
DB_POOL.get().expect("db_pool not initialized")
|
DB_POOL.get().expect("db_pool not initialized")
|
||||||
|
}
|
||||||
|
pub static RNEX_DATASTORE_S3_ENDPOINT: LazyLock<String> = LazyLock::new(|| {
|
||||||
|
std::env::var("RNEX_DATASTORE_S3_ENDPOINT")
|
||||||
|
.expect("RNEX_DATASTORE_S3_ENDPOINT must be set")
|
||||||
|
});
|
||||||
|
pub static RNEX_DATASTORE_S3_BUCKET: LazyLock<String> = LazyLock::new(|| {
|
||||||
|
std::env::var("RNEX_DATASTORE_S3_BUCKET")
|
||||||
|
.expect("RNEX_DATASTORE_S3_BUCKET must be set")
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub static RNEX_DATASTORE_S3_ENDPOINT: LazyLock<String> = LazyLock::new(|| {
|
|
||||||
std::env::var("RNEX_DATASTORE_S3_ENDPOINT")
|
|
||||||
.expect("RNEX_DATASTORE_S3_ENDPOINT must be set")
|
|
||||||
});
|
|
||||||
pub static RNEX_DATASTORE_S3_BUCKET: LazyLock<String> = LazyLock::new(|| {
|
|
||||||
std::env::var("RNEX_DATASTORE_S3_BUCKET")
|
|
||||||
.expect("RNEX_DATASTORE_S3_BUCKET must be set")
|
|
||||||
});
|
|
||||||
|
|
||||||
pub fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
|
pub fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
|
||||||
let mut req = ureq::get(IP_REQ_SERVICE_URL).call()?;
|
let mut req = ureq::get(IP_REQ_SERVICE_URL).call()?;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
pub mod account;
|
pub mod account;
|
||||||
pub mod auth_handler;
|
pub mod auth_handler;
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|
@ -6,4 +8,8 @@ pub mod matchmake;
|
||||||
pub mod remote_console;
|
pub mod remote_console;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
pub mod datastore;
|
pub mod datastore;
|
||||||
pub mod s3presigner;
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "datastore")] {
|
||||||
|
pub mod s3presigner;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -41,21 +41,37 @@ use rnex_core::prudp::socket_addr::PRUDPSockAddr;
|
||||||
use rnex_core::rmc::response::ErrorCode::{Core_InvalidArgument, RendezVous_AccountExpired};
|
use rnex_core::rmc::response::ErrorCode::{Core_InvalidArgument, RendezVous_AccountExpired};
|
||||||
use rnex_core::rmc::structures::qresult::QResult;
|
use rnex_core::rmc::structures::qresult::QResult;
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
|
use cfg_if::cfg_if;
|
||||||
use rnex_core::rmc::protocols::ranking::{CompetitionRankingScoreData, CompetitionRankingGetParam, CompetitionRankingScoreInfo};
|
use rnex_core::rmc::protocols::ranking::{CompetitionRankingScoreData, CompetitionRankingGetParam, CompetitionRankingScoreInfo};
|
||||||
use rnex_core::rmc::structures::ranking::{UploadCompetitionData};
|
use rnex_core::rmc::structures::ranking::{UploadCompetitionData};
|
||||||
use tokio::sync::{Mutex, RwLock};
|
use tokio::sync::{Mutex, RwLock};
|
||||||
|
|
||||||
define_rmc_proto!(
|
cfg_if! {
|
||||||
proto UserProtocol{
|
if #[cfg(feature = "datastore")] {
|
||||||
Secure,
|
define_rmc_proto!(
|
||||||
MatchmakeExtension,
|
proto UserProtocol{
|
||||||
MatchmakeExt,
|
Secure,
|
||||||
Matchmake,
|
MatchmakeExtension,
|
||||||
NatTraversal,
|
MatchmakeExt,
|
||||||
Ranking,
|
Matchmake,
|
||||||
DataStore
|
NatTraversal,
|
||||||
|
Ranking,
|
||||||
|
DataStore
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
define_rmc_proto!(
|
||||||
|
proto UserProtocol{
|
||||||
|
Secure,
|
||||||
|
MatchmakeExtension,
|
||||||
|
MatchmakeExt,
|
||||||
|
Matchmake,
|
||||||
|
NatTraversal,
|
||||||
|
Ranking
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
);
|
}
|
||||||
|
|
||||||
#[rmc_struct(UserProtocol)]
|
#[rmc_struct(UserProtocol)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue