diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-04 10:42:18 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-04 10:42:18 +0000 |
| commit | 9394657613014891ff91db6cd0a01b21bb257053 (patch) | |
| tree | e59ff64c5463039e4304928b3b24377e3e438822 /src/config.rs | |
| parent | 52bad9954cdddf55ab749fd0c6387edbc766632f (diff) | |
feat: implement NIP-01 compliant Nostr relay
- WebSocket-based relay using tokio-tungstenite
- Full NIP-01 protocol support (EVENT, REQ, CLOSE)
- Event validation (signature and ID)
- In-memory event storage
- Filter support (IDs, authors, kinds, since/until)
- Configuration via environment variables
- Nix flake for reproducible builds
- Test automation script
All 6 NIP-01 smoke tests passing (100%)
Diffstat (limited to 'src/config.rs')
| -rw-r--r-- | src/config.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..252873d --- /dev/null +++ b/src/config.rs | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | use anyhow::{Context, Result}; | ||
| 2 | use serde::{Deserialize, Serialize}; | ||
| 3 | use std::env; | ||
| 4 | |||
| 5 | #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| 6 | pub struct Config { | ||
| 7 | pub domain: String, | ||
| 8 | pub owner_npub: String, | ||
| 9 | pub relay_name: String, | ||
| 10 | pub relay_description: String, | ||
| 11 | pub git_data_path: String, | ||
| 12 | pub relay_data_path: String, | ||
| 13 | pub bind_address: String, | ||
| 14 | } | ||
| 15 | |||
| 16 | impl Config { | ||
| 17 | pub fn from_env() -> Result<Self> { | ||
| 18 | // Load .env file if present | ||
| 19 | dotenvy::dotenv().ok(); | ||
| 20 | |||
| 21 | Ok(Config { | ||
| 22 | domain: env::var("NGIT_DOMAIN") | ||
| 23 | .unwrap_or_else(|_| "localhost:8080".to_string()), | ||
| 24 | owner_npub: env::var("NGIT_OWNER_NPUB") | ||
| 25 | .context("NGIT_OWNER_NPUB must be set")?, | ||
| 26 | relay_name: env::var("NGIT_RELAY_NAME") | ||
| 27 | .unwrap_or_else(|_| "ngit-grasp relay".to_string()), | ||
| 28 | relay_description: env::var("NGIT_RELAY_DESCRIPTION") | ||
| 29 | .unwrap_or_else(|_| "A GRASP-compliant Nostr relay for Git".to_string()), | ||
| 30 | git_data_path: env::var("NGIT_GIT_DATA_PATH") | ||
| 31 | .unwrap_or_else(|_| "./data/git".to_string()), | ||
| 32 | relay_data_path: env::var("NGIT_RELAY_DATA_PATH") | ||
| 33 | .unwrap_or_else(|_| "./data/relay".to_string()), | ||
| 34 | bind_address: env::var("NGIT_BIND_ADDRESS") | ||
| 35 | .unwrap_or_else(|_| "127.0.0.1:8080".to_string()), | ||
| 36 | }) | ||
| 37 | } | ||
| 38 | } | ||