1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum ResCode {
8 Success = 1000,
10 CommFail = 1001,
12 ValidateFail = 1002,
14 CoreFail = 1003,
16}
17
18impl ResCode {
19 pub fn as_u32(self) -> u32 {
21 self as u32
22 }
23}
24
25#[derive(Debug, Clone)]
27pub struct ResMessage;
28
29impl ResMessage {
30 pub const SUCCESS: &'static str = "success";
32 pub const COMM_FAIL: &'static str = "comm fail";
34 pub const VALIDATE_FAIL: &'static str = "validate fail";
36 pub const CORE_FAIL: &'static str = "core fail";
38}
39
40#[derive(Debug, Clone)]
42pub struct ErrInfo;
43
44impl ErrInfo {
45 pub const NO_ENTITY: &'static str = "未设置操作实体";
47 pub const NO_ID: &'static str = "查询参数[id]不存在";
49 pub const SORT_FIELD: &'static str = "排序参数不正确";
51}
52
53#[derive(Debug, Clone)]
55pub struct Event;
56
57impl Event {
58 pub const SOFT_DELETE: &'static str = "onSoftDelete";
60 pub const SERVER_READY: &'static str = "onServerReady";
62 pub const READY: &'static str = "onReady";
64 pub const ES_DATA_CHANGE: &'static str = "esDataChange";
66}
67
68pub struct GlobalConfig {
72 res_code: ResCodeConfig,
73 res_message: ResMessageConfig,
74}
75
76pub struct ResCodeConfig {
77 success: u32,
78 comm_fail: u32,
79 validate_fail: u32,
80 core_fail: u32,
81}
82
83pub struct ResMessageConfig {
84 success: String,
85 comm_fail: String,
86 validate_fail: String,
87 core_fail: String,
88}
89
90impl GlobalConfig {
91 pub fn get_instance() -> &'static GlobalConfig {
93 static INSTANCE: once_cell::sync::Lazy<GlobalConfig> =
94 once_cell::sync::Lazy::new(|| GlobalConfig {
95 res_code: ResCodeConfig {
96 success: 1000,
97 comm_fail: 1001,
98 validate_fail: 1002,
99 core_fail: 1003,
100 },
101 res_message: ResMessageConfig {
102 success: "success".to_string(),
103 comm_fail: "comm fail".to_string(),
104 validate_fail: "validate fail".to_string(),
105 core_fail: "core fail".to_string(),
106 },
107 });
108 &INSTANCE
109 }
110
111 pub fn res_code(&self) -> &ResCodeConfig {
113 &self.res_code
114 }
115
116 pub fn res_message(&self) -> &ResMessageConfig {
118 &self.res_message
119 }
120}
121
122impl ResCodeConfig {
123 pub fn success(&self) -> u32 {
124 self.success
125 }
126
127 pub fn comm_fail(&self) -> u32 {
128 self.comm_fail
129 }
130
131 pub fn validate_fail(&self) -> u32 {
132 self.validate_fail
133 }
134
135 pub fn core_fail(&self) -> u32 {
136 self.core_fail
137 }
138}
139
140impl ResMessageConfig {
141 pub fn success(&self) -> &str {
142 &self.success
143 }
144
145 pub fn comm_fail(&self) -> &str {
146 &self.comm_fail
147 }
148
149 pub fn validate_fail(&self) -> &str {
150 &self.validate_fail
151 }
152
153 pub fn core_fail(&self) -> &str {
154 &self.core_fail
155 }
156}