0.6 rust重构01
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
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 不能为空"));
|
||||
}
|
||||
if context
|
||||
.workspace_id
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.trim()
|
||||
.is_empty()
|
||||
{
|
||||
return Err(BridgeError::validation("workspace_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(())
|
||||
}
|
||||
Reference in New Issue
Block a user