mirror of
https://github.com/mikedilger/chorus.git
synced 2026-08-01 07:21:39 +00:00
NostrReply
This commit is contained in:
parent
a1bcec359c
commit
f249fae274
@ -3,6 +3,7 @@ include!("macros.rs");
|
||||
pub mod config;
|
||||
pub mod error;
|
||||
pub mod globals;
|
||||
pub mod reply;
|
||||
pub mod store;
|
||||
pub mod tls;
|
||||
pub mod types;
|
||||
|
||||
28
src/reply.rs
Normal file
28
src/reply.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use crate::types::{Event, Id};
|
||||
use std::fmt;
|
||||
|
||||
pub enum NostrReply<'a> {
|
||||
Event(&'a str, Event<'a>),
|
||||
Ok(Id, bool, String),
|
||||
Eose(&'a str),
|
||||
Closed(&'a str, String),
|
||||
Notice(String),
|
||||
}
|
||||
|
||||
impl NostrReply<'_> {
|
||||
pub fn as_json(&self) -> String {
|
||||
match self {
|
||||
NostrReply::Event(subid, event) => format!(r#"["EVENT", "{subid}", {}]"#, event),
|
||||
NostrReply::Ok(id, ok, msg) => format!(r#"["OK","{id}",{ok},"{msg}"]"#),
|
||||
NostrReply::Eose(subid) => format!(r#"["EOSE","{subid}"]"#),
|
||||
NostrReply::Closed(subid, msg) => format!(r#"["CLOSED","{subid}","{msg}"]"#),
|
||||
NostrReply::Notice(msg) => format!(r#"["NOTICE","{msg}"]"#),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for NostrReply<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", self.as_json())
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user