42 lines
1.3 KiB
Rust
42 lines
1.3 KiB
Rust
use crate::context::BridgeContext;
|
|||
|
|
use crate::types::{BridgeError, BridgeResult};
|
||
|
|
use core_protocol::{CommandEnvelope, QueryEnvelope};
|
||
|
|
|
||
|
|
pub fn validate_command_envelope<T>(
|
||
|
|
context: &BridgeContext,
|
||
|
|
command: &CommandEnvelope<T>,
|
||
|
|
) -> BridgeResult<()> {
|
||
|
|
if command.name.trim().is_empty() {
|
||
|
|
return Err(BridgeError::validation("command name 不能为空"));
|
||
|
|
}
|
||
|
|
if command.command_id.trim().is_empty() {
|
||
|
|
return Err(BridgeError::validation("command_id 不能为空"));
|
||
|
|
}
|
||
|
|
if context.request_id.trim().is_empty() {
|
||
|
|
return Err(BridgeError::validation("request_id 不能为空"));
|
||
|
|
}
|
||
|
|
if context.trace_id.trim().is_empty() {
|
||
|
|
return Err(BridgeError::validation("trace_id 不能为空"));
|
||
|
|
}
|
||
|
|
if context.actor_id.trim().is_empty() {
|
||
|
|
return Err(BridgeError::validation("actor_id 不能为空"));
|
||
|
|
}
|
||
|
|
Ok(())
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn validate_query_envelope<T>(
|
||
|
|
context: &BridgeContext,
|
||
|
|
query: &QueryEnvelope<T>,
|
||
|
|
) -> BridgeResult<()> {
|
||
|
|
if query.name.trim().is_empty() {
|
||
|
|
return Err(BridgeError::validation("query name 不能为空"));
|
||
|
|
}
|
||
|
|
if context.request_id.trim().is_empty() {
|
||
|
|
return Err(BridgeError::validation("request_id 不能为空"));
|
||
|
|
}
|
||
|
|
if context.trace_id.trim().is_empty() {
|
||
|
|
return Err(BridgeError::validation("trace_id 不能为空"));
|
||
|
|
}
|
||
|
|
Ok(())
|
||
|
|
}
|