new(all): Initial import.
This commit is contained in:
parent
cbc762c512
commit
df7c776edb
4 changed files with 148 additions and 1 deletions
58
.vscode/launch.json
vendored
Normal file
58
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug GB API Server",
|
||||||
|
"cargo": {
|
||||||
|
"args": ["build", "--bin=gb-api"],
|
||||||
|
"filter": {
|
||||||
|
"name": "gb-api",
|
||||||
|
"kind": "bin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"env": {
|
||||||
|
"RUST_LOG": "debug",
|
||||||
|
"DATABASE_URL": "postgresql://localhost:5432/gbdb",
|
||||||
|
"REDIS_URL": "redis://localhost:6379"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug GB API Tests",
|
||||||
|
"cargo": {
|
||||||
|
"args": ["test", "--package=gb-api", "--lib"],
|
||||||
|
"filter": {
|
||||||
|
"name": "gb-api",
|
||||||
|
"kind": "lib"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Debug Integration Tests",
|
||||||
|
"cargo": {
|
||||||
|
"args": ["test", "--package=gb-api", "--test=integration"],
|
||||||
|
"filter": {
|
||||||
|
"name": "integration",
|
||||||
|
"kind": "test"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"compounds": [
|
||||||
|
{
|
||||||
|
"name": "API Server + Debug",
|
||||||
|
"configurations": ["Debug GB API Server"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2363,6 +2363,7 @@ dependencies = [
|
||||||
"tower 0.4.13",
|
"tower 0.4.13",
|
||||||
"tower-http 0.5.2",
|
"tower-http 0.5.2",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"tracing-subscriber",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ license = { workspace = true }
|
||||||
gb-core = { path = "../gb-core" }
|
gb-core = { path = "../gb-core" }
|
||||||
gb-messaging = { path = "../gb-messaging" }
|
gb-messaging = { path = "../gb-messaging" }
|
||||||
gb-monitoring = { path = "../gb-monitoring" }
|
gb-monitoring = { path = "../gb-monitoring" }
|
||||||
tokio= { workspace = true }
|
tokio = { version = "1.0", features = ["full", "macros", "rt-multi-thread"] } # Add these features
|
||||||
axum = { version = "0.7.9", features = ["ws", "multipart", "macros"] }
|
axum = { version = "0.7.9", features = ["ws", "multipart", "macros"] }
|
||||||
tower= { workspace = true }
|
tower= { workspace = true }
|
||||||
tower-http = { version = "0.5", features = ["cors", "trace"] }
|
tower-http = { version = "0.5", features = ["cors", "trace"] }
|
||||||
|
@ -17,6 +17,7 @@ serde= { workspace = true }
|
||||||
serde_json= { workspace = true }
|
serde_json= { workspace = true }
|
||||||
uuid= { workspace = true }
|
uuid= { workspace = true }
|
||||||
tracing= { workspace = true }
|
tracing= { workspace = true }
|
||||||
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||||
async-trait= { workspace = true }
|
async-trait= { workspace = true }
|
||||||
futures-util = { version = "0.3", features = ["sink"] }
|
futures-util = { version = "0.3", features = ["sink"] }
|
||||||
chrono = { workspace = true, features = ["serde"] }
|
chrono = { workspace = true, features = ["serde"] }
|
||||||
|
|
87
gb-api/src/main.rs
Normal file
87
gb-api/src/main.rs
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
use gb_core::{Error, Result};
|
||||||
|
use gb_core::models::Customer;
|
||||||
|
use tracing::{info, error};
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<()> {
|
||||||
|
// Initialize logging first
|
||||||
|
init_logging()?;
|
||||||
|
|
||||||
|
// Initialize core components
|
||||||
|
let app = initialize_bot_server().await?;
|
||||||
|
|
||||||
|
// Start the server
|
||||||
|
start_server(app).await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn initialize_bot_server() -> Result<axum::Router> {
|
||||||
|
info!("Initializing General Bots...");
|
||||||
|
|
||||||
|
// Initialize database connections
|
||||||
|
let db_pool = initialize_database().await?;
|
||||||
|
|
||||||
|
// Initialize Redis
|
||||||
|
let redis_client = initialize_redis().await?;
|
||||||
|
|
||||||
|
// Build the Axum router with our routes
|
||||||
|
let app = axum::Router::new()
|
||||||
|
.with_state(AppState {
|
||||||
|
db: db_pool,
|
||||||
|
redis: redis_client,
|
||||||
|
})
|
||||||
|
// Add your route handlers here
|
||||||
|
.layer(tower_http::trace::TraceLayer::new_for_http());
|
||||||
|
|
||||||
|
Ok(app)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init_logging() -> Result<()> {
|
||||||
|
use tracing_subscriber::{EnvFilter, fmt};
|
||||||
|
|
||||||
|
let env_filter = EnvFilter::try_from_default_env()
|
||||||
|
.unwrap_or_else(|_| EnvFilter::new("info"));
|
||||||
|
|
||||||
|
tracing_subscriber::fmt()
|
||||||
|
.with_env_filter(env_filter)
|
||||||
|
.with_file(true)
|
||||||
|
.with_line_number(true)
|
||||||
|
.with_thread_ids(true)
|
||||||
|
.init();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn initialize_database() -> Result<sqlx::PgPool> {
|
||||||
|
let database_url = std::env::var("DATABASE_URL")
|
||||||
|
.map_err(|_| Error::Configuration("DATABASE_URL not set".into()))?;
|
||||||
|
|
||||||
|
sqlx::PgPool::connect(&database_url)
|
||||||
|
.await
|
||||||
|
.map_err(|e| Error::Database(e.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn initialize_redis() -> Result<redis::Client> {
|
||||||
|
let redis_url = std::env::var("REDIS_URL")
|
||||||
|
.map_err(|_| Error::Configuration("REDIS_URL not set".into()))?;
|
||||||
|
|
||||||
|
redis::Client::open(redis_url)
|
||||||
|
.map_err(|e| Error::Cache(e.to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct AppState {
|
||||||
|
db: sqlx::PgPool,
|
||||||
|
redis: redis::Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn start_server(app: axum::Router) -> Result<()> {
|
||||||
|
let addr = std::net::SocketAddr::from(([0, 0, 0, 0], 3000));
|
||||||
|
info!("Starting server on {}", addr);
|
||||||
|
|
||||||
|
axum::Server::bind(&addr)
|
||||||
|
.serve(app.into_make_service())
|
||||||
|
.await
|
||||||
|
.map_err(|e| Error::Server(e.to_string()))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue