@@ -97,7 +97,7 @@ impl_oapi_endpoint_out!(OK, "text/plain");
9797#[ cfg( feature = "salvo" ) ]
9898#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
9999#[ macro_export]
100- macro_rules! ok { ( ) => { Ok ( OK ( $crate:: fn_name!( ) ) ) } ; }
100+ macro_rules! ok { ( ) => { Ok ( cc_utils :: responses :: OK ( $crate:: fn_name!( ) ) ) } }
101101
102102#[ cfg( feature = "salvo" ) ]
103103#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
@@ -106,7 +106,7 @@ impl ServerResponseWriter for OK {
106106 async fn write ( self , _req : & mut Request , _depot : & mut Depot , res : & mut Response ) {
107107 res. status_code ( StatusCode :: OK ) ;
108108 res. render ( "" ) ;
109- log :: debug!( "[{}] => Received and sent result 200" , self . 0 ) ;
109+ tracing :: debug!( "[{}] => Received and sent result 200" , self . 0 ) ;
110110 }
111111}
112112
@@ -123,7 +123,7 @@ impl_oapi_endpoint_out!(Plain, "text/plain");
123123#[ cfg( feature = "salvo" ) ]
124124#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
125125#[ macro_export]
126- macro_rules! plain { ( $plain_text: expr) => { Ok ( Plain ( $plain_text, $crate:: fn_name!( ) ) ) } ; }
126+ macro_rules! plain { ( $plain_text: expr) => { Ok ( cc_utils :: responses :: Plain ( $plain_text, $crate:: fn_name!( ) ) ) } }
127127
128128#[ cfg( feature = "salvo" ) ]
129129#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
@@ -132,7 +132,7 @@ impl ServerResponseWriter for Plain {
132132 async fn write ( self , _req : & mut Request , _depot : & mut Depot , res : & mut Response ) {
133133 res. status_code ( StatusCode :: OK ) ;
134134 res. render ( & self . 0 ) ;
135- log :: debug!( "[{}] => Received and sent result 200 with text: {}" , self . 1 , self . 0 ) ;
135+ tracing :: debug!( "[{}] => Received and sent result 200 with text: {}" , self . 1 , self . 0 ) ;
136136 }
137137}
138138
@@ -149,7 +149,7 @@ impl_oapi_endpoint_out!(Html, "text/html");
149149#[ cfg( feature = "salvo" ) ]
150150#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
151151#[ macro_export]
152- macro_rules! html { ( $html_data: expr) => { Ok ( Html ( $html_data, $crate:: fn_name!( ) ) ) } ; }
152+ macro_rules! html { ( $html_data: expr) => { Ok ( cc_utils :: responses :: Html ( $html_data, $crate:: fn_name!( ) ) ) } }
153153
154154#[ cfg( feature = "salvo" ) ]
155155#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
@@ -158,7 +158,7 @@ impl ServerResponseWriter for Html {
158158 async fn write ( self , _req : & mut Request , _depot : & mut Depot , res : & mut Response ) {
159159 res. status_code ( StatusCode :: OK ) ;
160160 res. render ( salvo:: writing:: Text :: Html ( & self . 0 ) ) ;
161- log :: debug!( "[{}] => Received and sent result 200 with HTML" , self . 1 ) ;
161+ tracing :: debug!( "[{}] => Received and sent result 200 with HTML" , self . 1 ) ;
162162 }
163163}
164164
@@ -181,13 +181,13 @@ impl_oapi_endpoint_out!(File, "application/octet-stream");
181181/// use salvo::prelude::*;
182182///
183183/// pub async fn some_endpoint() -> MResult<File> {
184- /// file !("filepath", "Normal file name")
184+ /// file_upload !("filepath".to_string() , "Normal file name".to_string() )
185185/// }
186186/// ```
187187#[ cfg( feature = "salvo" ) ]
188188#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
189189#[ macro_export]
190- macro_rules! file { ( $filepath: expr, $attached_filename: expr) => { Ok ( File ( $filepath, $attached_filename, $crate:: fn_name!( ) ) ) } ; }
190+ macro_rules! file_upload { ( $filepath: expr, $attached_filename: expr) => { Ok ( cc_utils :: responses :: File ( $filepath, $attached_filename, $crate:: fn_name!( ) ) ) } }
191191
192192#[ cfg( feature = "salvo" ) ]
193193#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
@@ -196,7 +196,7 @@ impl ServerResponseWriter for File {
196196 async fn write ( self , req : & mut Request , _depot : & mut Depot , res : & mut Response ) {
197197 res. status_code ( StatusCode :: OK ) ;
198198 NamedFile :: builder ( & self . 0 ) . attached_name ( & self . 1 ) . use_last_modified ( true ) . send ( req. headers ( ) , res) . await ;
199- log :: debug!( "[{}] => Received and sent result 200 with file {}" , self . 2 , self . 1 ) ;
199+ tracing :: debug!( "[{}] => Received and sent result 200 with file {}" , self . 2 , self . 1 ) ;
200200 }
201201}
202202
@@ -213,7 +213,7 @@ impl_oapi_endpoint_out_t!(Json, "application/json");
213213#[ cfg( feature = "salvo" ) ]
214214#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
215215#[ macro_export]
216- macro_rules! json { ( $json_data: expr) => { Ok ( Json ( $json_data, $crate:: fn_name!( ) ) ) } ; }
216+ macro_rules! json { ( $json_data: expr) => { Ok ( cc_utils :: responses :: Json ( $json_data, $crate:: fn_name!( ) ) ) } }
217217
218218#[ cfg( feature = "salvo" ) ]
219219#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
@@ -224,16 +224,15 @@ impl<T: Serialize + Send> ServerResponseWriter for Json<T> {
224224 match serde_json:: to_string ( & self . 0 ) {
225225 Ok ( s) => {
226226 res. headers_mut ( ) . insert ( CONTENT_TYPE , HeaderValue :: from_static ( "application/json; charset=utf-8" ) ) ;
227- log :: debug!( "[{}] => Sending JSON: {:?}" , self . 1 , s. as_str( ) ) ;
227+ tracing :: debug!( "[{}] => Sending JSON: {:?}" , self . 1 , s. as_str( ) ) ;
228228 res. write_body ( s) . ok ( ) ;
229- log :: debug!( "[{}] => Received and sent result 200 with JSON" , self . 1 ) ;
229+ tracing :: debug!( "[{}] => Received and sent result 200 with JSON" , self . 1 ) ;
230230 }
231231 Err ( e) => {
232- log :: error!( "[{}] => Failed to serialize data: {:?}" , e, self . 1 ) ;
232+ tracing :: error!( "[{}] => Failed to serialize data: {:?}" , e, self . 1 ) ;
233233 ErrorResponse :: from ( "Failed to serialize data." ) . with_500 ( ) . build ( ) . write ( req, depot, res) . await ;
234234 }
235235 }
236- log:: debug!( "[{}] => Received and sent result 200 with JSON" , self . 1 ) ;
237236 }
238237}
239238
@@ -250,7 +249,7 @@ impl_oapi_endpoint_out_t!(MsgPack, "application/msgpack");
250249#[ cfg( feature = "salvo" ) ]
251250#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
252251#[ macro_export]
253- macro_rules! msgpack { ( $msgpack_data: expr) => { Ok ( MsgPack ( $msgpack_data, $crate:: fn_name!( ) ) ) } ; }
252+ macro_rules! msgpack { ( $msgpack_data: expr) => { Ok ( cc_utils :: responses :: MsgPack ( $msgpack_data, $crate:: fn_name!( ) ) ) } }
254253
255254#[ cfg( feature = "salvo" ) ]
256255#[ cfg( not( any( target_arch = "wasm32" , target_arch = "wasm64" ) ) ) ]
@@ -261,12 +260,12 @@ impl<T: Serialize + Send> ServerResponseWriter for MsgPack<T> {
261260 match rmp_serde:: to_vec ( & self . 0 ) {
262261 Ok ( bytes) => {
263262 res. headers_mut ( ) . insert ( CONTENT_TYPE , HeaderValue :: from_static ( "application/msgpack; charset=utf-8" ) ) ;
264- log :: debug!( "[{}] => Sending bytes: {:?}" , self . 1 , bytes) ;
263+ tracing :: debug!( "[{}] => Sending bytes: {:?}" , self . 1 , bytes) ;
265264 res. write_body ( bytes) . ok ( ) ;
266- log :: debug!( "[{}] => Received and sent result 200 with MsgPack" , self . 1 ) ;
265+ tracing :: debug!( "[{}] => Received and sent result 200 with MsgPack" , self . 1 ) ;
267266 }
268267 Err ( e) => {
269- log :: error!( "[{}] => Failed to serialize data: {:?}" , e, self . 1 ) ;
268+ tracing :: error!( "[{}] => Failed to serialize data: {:?}" , e, self . 1 ) ;
270269 ErrorResponse :: from ( "Failed to serialize data." ) . with_500 ( ) . build ( ) . write ( req, depot, res) . await ;
271270 }
272271 }
0 commit comments