From be9599edac838619d7e9aeffd067e2e56468e97a Mon Sep 17 00:00:00 2001 From: shenghui0779 Date: Tue, 29 Oct 2024 17:17:13 +0800 Subject: [PATCH] Update ApiResult --- Cargo.lock | 289 +++++++++++----------- README.md | 7 +- src/app/api/auth.rs | 4 +- src/app/middleware/auth.rs | 2 +- src/app/service/account.rs | 8 +- src/app/service/auth.rs | 6 +- src/app/service/project.rs | 8 +- src/shared/middleware/catch_panic.rs | 2 +- src/shared/middleware/log.rs | 2 +- src/shared/middleware/trace.rs | 6 +- src/shared/result/code.rs | 8 +- src/shared/result/mod.rs | 4 +- src/shared/result/{status.rs => reply.rs} | 8 +- src/shared/util/identity.rs | 3 + 14 files changed, 180 insertions(+), 177 deletions(-) rename src/shared/result/{status.rs => reply.rs} (85%) diff --git a/Cargo.lock b/Cargo.lock index fa19871..c8d3167 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,9 +113,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.15" +version = "0.6.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +checksum = "23a1e53f0f5d86382dafe1cf314783b2044280f406e7e1506368220ad11b1338" dependencies = [ "anstyle", "anstyle-parse", @@ -128,43 +128,43 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "8365de52b16c035ff4fcafe0092ba9390540e3e352870ac09933bebcaa2c8c56" [[package]] name = "anstyle-parse" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.4" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anyhow" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" +checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8" [[package]] name = "arc-swap" @@ -172,6 +172,12 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" +[[package]] +name = "arraydeque" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" + [[package]] name = "arrayvec" version = "0.7.6" @@ -197,7 +203,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -208,7 +214,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -267,9 +273,9 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bigdecimal" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d712318a27c7150326677b321a5fa91b55f6d9034ffd67f20319e147d40cee" +checksum = "8f850665a0385e070b64c38d2354e6c104c8479c59868d1e48a0c13ee2c7a1c1" dependencies = [ "autocfg", "libm", @@ -329,7 +335,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", "syn_derive", ] @@ -369,15 +375,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" [[package]] name = "cc" -version = "1.1.30" +version = "1.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945" +checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" dependencies = [ "shlex", ] @@ -448,7 +454,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -459,9 +465,9 @@ checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "colorchoice" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "combine" @@ -488,14 +494,13 @@ dependencies = [ [[package]] name = "config" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7328b20597b53c2454f0b1919720c25c7339051c02b72b7e05409e00b14132be" +checksum = "68578f196d2a33ff61b27fae256c3164f65e36382648e30666dde05b8cc9dfdf" dependencies = [ "async-trait", "convert_case", "json5", - "lazy_static", "nom", "pathdiff", "ron", @@ -503,7 +508,7 @@ dependencies = [ "serde", "serde_json", "toml", - "yaml-rust", + "yaml-rust2", ] [[package]] @@ -726,9 +731,9 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.34" +version = "0.8.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" dependencies = [ "cfg-if", ] @@ -750,7 +755,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -799,9 +804,9 @@ checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "flume" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55ac459de2512911e4b674ce33cf20befaba382d05b62b008afc1c8b57cbf181" +checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095" dependencies = [ "futures-core", "futures-sink", @@ -911,7 +916,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -1017,12 +1022,6 @@ dependencies = [ "ahash 0.7.8", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" - [[package]] name = "hashbrown" version = "0.14.5" @@ -1039,6 +1038,15 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +[[package]] +name = "hashlink" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" +dependencies = [ + "hashbrown 0.14.5", +] + [[package]] name = "hashlink" version = "0.9.1" @@ -1182,9 +1190,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +checksum = "bbbff0a806a4728c99295b254c8838933b5b082d75e3cb70c8dab21fdfbcfa9a" dependencies = [ "bytes", "futures-channel", @@ -1238,9 +1246,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" +checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" dependencies = [ "bytes", "futures-channel", @@ -1322,7 +1330,7 @@ checksum = "0122b7114117e64a63ac49f752a5ca4624d534c7b1c7de796ac196381cd2d947" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -1407,15 +1415,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.159" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libm" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "libsqlite3-sys" @@ -1428,12 +1436,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linked-hash-map" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" - [[package]] name = "linux-raw-sys" version = "0.4.14" @@ -1474,9 +1476,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "metrics" -version = "0.22.3" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2be3cbd384d4e955b231c895ce10685e3d8260c5ccffae898c96c723b0772835" +checksum = "884adb57038347dfbaf2d5065887b6cf4312330dc8e94bc30a1a839bd79d3261" dependencies = [ "ahash 0.8.11", "portable-atomic", @@ -1527,9 +1529,9 @@ dependencies = [ [[package]] name = "mobc" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8d3681f0b299413df040f53c6950de82e48a8e1a9f79d442ed1ad3694d660b9" +checksum = "316a7d198b51958a0ab57248bf5f42d8409551203cb3c821d5925819a8d5415f" dependencies = [ "async-trait", "futures-channel", @@ -1723,9 +1725,9 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.66" +version = "0.10.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" +checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" dependencies = [ "bitflags", "cfg-if", @@ -1744,7 +1746,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -1755,18 +1757,18 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "300.3.2+3.3.2" +version = "300.4.0+3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a211a18d945ef7e648cc6e0058f4c548ee46aab922ea203e0d30e966ea23647b" +checksum = "a709e02f2b4aca747929cca5ed248880847c650233cf8b8cdc48f40aaf4898a6" dependencies = [ "cc", ] [[package]] name = "openssl-sys" -version = "0.9.103" +version = "0.9.104" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" +checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" dependencies = [ "cc", "libc", @@ -1786,12 +1788,12 @@ dependencies = [ [[package]] name = "ordered-multimap" -version = "0.6.0" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ed8acf08e98e744e5384c8bc63ceb0364e68a6854187221c18df61c4797690e" +checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79" dependencies = [ "dlv-list", - "hashbrown 0.13.2", + "hashbrown 0.14.5", ] [[package]] @@ -1816,7 +1818,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -1922,7 +1924,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -1938,29 +1940,29 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" +checksum = "be57f64e946e500c8ee36ef6331845d40a93055567ec57e8fae13efd33759b95" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" +checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] name = "pin-project-lite" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "pin-utils" @@ -2080,14 +2082,14 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] @@ -2100,7 +2102,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", "version_check", "yansi", ] @@ -2208,9 +2210,9 @@ dependencies = [ [[package]] name = "redis" -version = "0.27.4" +version = "0.27.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6baebe319ef5e4b470f248335620098d1c2e9261e995be05f56f719ca4bdb2" +checksum = "81cccf17a692ce51b86564334614d72dcae1def0fd5ecebc9f02956da74352b5" dependencies = [ "arc-swap", "async-trait", @@ -2245,9 +2247,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -2283,9 +2285,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.8" +version = "0.12.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" dependencies = [ "base64 0.22.1", "bytes", @@ -2404,9 +2406,9 @@ dependencies = [ [[package]] name = "rust-ini" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e2a3bcec1f113553ef1c88aae6c020a369d03d55b58de9869a0908930385091" +checksum = "3e0698206bcb8882bf2a9ecb4c1e7785db57ff052297085a6efd4fe42302068a" dependencies = [ "cfg-if", "ordered-multimap", @@ -2436,9 +2438,9 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustix" -version = "0.38.37" +version = "0.38.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +checksum = "aa260229e6538e52293eeb577aabd09945a09d6d9cc0fc550ed7529056c2e32a" dependencies = [ "bitflags", "errno", @@ -2449,9 +2451,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.14" +version = "0.23.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "415d9944693cb90382053259f89fbb077ea730ad7273047ec63b19bc9b160ba8" +checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" dependencies = [ "log", "once_cell", @@ -2486,9 +2488,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" +checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" [[package]] name = "rustls-webpki" @@ -2576,7 +2578,7 @@ checksum = "6f568f3050f43e828615121a27ae38450987d3d6aa8ac072dce6d3171df6b383" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -2634,7 +2636,7 @@ dependencies = [ "quote", "regex", "salvo-serde-util", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -2671,7 +2673,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -2712,15 +2714,15 @@ dependencies = [ "proc-macro2", "quote", "sea-bae", - "syn 2.0.79", + "syn 2.0.85", "unicode-ident", ] [[package]] name = "sea-query" -version = "0.32.0-rc.2" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ae69162bc417008f7ba60abd5c2688529cd83e99a9ab680d922b41fd9bf3d8d" +checksum = "ff504d13b5e4b52fffcf2fb203d0352a5722fa5151696db768933e41e1e591bb" dependencies = [ "bigdecimal", "chrono", @@ -2734,9 +2736,9 @@ dependencies = [ [[package]] name = "sea-query-binder" -version = "0.7.0-rc.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643c2e6fbba4440ff0075c405d37079a7da1a46892623b1cc8f06e05233eee1b" +checksum = "b0019f47430f7995af63deda77e238c17323359af241233ec768aba1faea7608" dependencies = [ "bigdecimal", "chrono", @@ -2779,9 +2781,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.210" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] @@ -2800,20 +2802,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", "memchr", @@ -3013,7 +3015,7 @@ dependencies = [ "futures-io", "futures-util", "hashbrown 0.14.5", - "hashlink", + "hashlink 0.9.1", "hex", "indexmap", "log", @@ -3049,7 +3051,7 @@ dependencies = [ "quote", "sqlx-core", "sqlx-macros-core", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -3072,7 +3074,7 @@ dependencies = [ "sqlx-mysql", "sqlx-postgres", "sqlx-sqlite", - "syn 2.0.79", + "syn 2.0.85", "tempfile", "tokio", "url", @@ -3243,9 +3245,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" dependencies = [ "proc-macro2", "quote", @@ -3261,7 +3263,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -3315,22 +3317,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.64" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.64" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -3402,9 +3404,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.40.0" +version = "1.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +checksum = "145f3413504347a2be84393cc8a7d2fb4d863b375909ea59f2158261aa258bbb" dependencies = [ "backtrace", "bytes", @@ -3426,7 +3428,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -3546,7 +3548,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] @@ -3623,12 +3625,9 @@ checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" [[package]] name = "unicase" -version = "2.7.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" -dependencies = [ - "version_check", -] +checksum = "7e51b68083f157f853b6379db119d1c1be0e6e4dec98101079dec41f6f5cf6df" [[package]] name = "unicode-bidi" @@ -3704,9 +3703,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" dependencies = [ "serde", ] @@ -3814,7 +3813,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", "wasm-bindgen-shared", ] @@ -3848,7 +3847,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3861,9 +3860,9 @@ checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "wasm-streams" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e072d4e72f700fb3443d8fe94a39315df013eef1104903cdb0a2abd322bbecd" +checksum = "15053d8d85c7eccdbefef60f06769760a563c7f0a9d6902a13d35c7800b0ad65" dependencies = [ "futures-util", "js-sys", @@ -4145,12 +4144,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af4e2e2f7cba5a093896c1e150fbfe177d1883e7448200efb81d40b9d339ef26" [[package]] -name = "yaml-rust" -version = "0.4.5" +name = "yaml-rust2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +checksum = "8902160c4e6f2fb145dbe9d6760a75e3c9522d8bf796ed7047c85919ac7115f8" dependencies = [ - "linked-hash-map", + "arraydeque", + "encoding_rs", + "hashlink 0.8.4", ] [[package]] @@ -4217,7 +4218,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.85", ] [[package]] diff --git a/README.md b/README.md index a83358b..c9e15b3 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # yiirs -Rust API 快速开发脚手架 +基于 [salvo](https://github.com/salvo-rs/salvo) 的 Rust API 快速开发脚手架 -- 路由使用 [salvo](https://github.com/salvo-rs/salvo) - ORM使用 [sea-orm](https://github.com/SeaQL/sea-orm) - Redis使用 [redis-rs](https://github.com/redis-rs/redis-rs) - 日志使用 [tracing](https://github.com/tokio-rs/tracing) @@ -13,7 +12,7 @@ Rust API 快速开发脚手架 - 包含基础的登录授权功能 - 包含基于 Redis 的分布式锁 - 包含 AES、Hash、时间格式化 等实用封装 -- 包含 Trace、认证、请求日志 中间价 +- 包含 Trace、认证、请求日志、Panic捕获 中间价 - 简单好用的 API Result 统一输出方式 #### 1. 模块说明 @@ -31,5 +30,5 @@ demo_rs.sql mv config.toml.example config.toml # 启动服务 -cargo run -- serve +cargo run serve ``` diff --git a/src/app/api/auth.rs b/src/app/api/auth.rs index 755c479..cb1b956 100644 --- a/src/app/api/auth.rs +++ b/src/app/api/auth.rs @@ -2,7 +2,7 @@ use salvo::{handler, Request}; use validator::Validate; use crate::shared::{ - result::{code::Code, status, ApiResult}, + result::{code::Code, reply, ApiResult}, util::identity::Identity, }; @@ -28,7 +28,7 @@ pub async fn logout(req: &mut Request) -> ApiResult<()> { let empty = Identity::empty(); let id = req.extensions().get::().unwrap_or(&empty); if id.id() == 0 { - return Ok(status::OK(None)); + return Ok(reply::OK(None)); } service::auth::logout(id).await } diff --git a/src/app/middleware/auth.rs b/src/app/middleware/auth.rs index 3c5f550..a506d81 100644 --- a/src/app/middleware/auth.rs +++ b/src/app/middleware/auth.rs @@ -25,7 +25,7 @@ impl Handler for Auth { let empty = Identity::empty(); let id = req.extensions().get::().unwrap_or(&empty); if let Err(e) = auth_check(id).await { - resp.render(Json(Code::ErrAuth(Some(e.to_string())).to_status())); + resp.render(Json(Code::ErrAuth(Some(e.to_string())).to_reply())); ctrl.skip_rest(); return; } diff --git a/src/app/service/account.rs b/src/app/service/account.rs index ff3d433..fa7825c 100644 --- a/src/app/service/account.rs +++ b/src/app/service/account.rs @@ -8,7 +8,7 @@ use validator::Validate; use crate::shared::core::db; use crate::shared::crypto::hash; use crate::shared::result::code::Code; -use crate::shared::result::{status, ApiResult}; +use crate::shared::result::{reply, ApiResult}; use crate::shared::util::{helper, xtime}; use crate::app::model::{account, prelude::Account}; @@ -55,7 +55,7 @@ pub async fn create(req: ReqCreate) -> ApiResult<()> { return Err(Code::ErrSystem(None)); } - Ok(status::OK(None)) + Ok(reply::OK(None)) } #[derive(Debug, Serialize)] @@ -90,7 +90,7 @@ pub async fn info(account_id: u64) -> ApiResult { .unwrap_or_default(), }; - Ok(status::OK(Some(resp))) + Ok(reply::OK(Some(resp))) } #[derive(Debug, Serialize)] @@ -154,5 +154,5 @@ pub async fn list(query: &MultiMap) -> ApiResult { resp.list.push(info); } - Ok(status::OK(Some(resp))) + Ok(reply::OK(Some(resp))) } diff --git a/src/app/service/auth.rs b/src/app/service/auth.rs index edb5d58..af79a3d 100644 --- a/src/app/service/auth.rs +++ b/src/app/service/auth.rs @@ -7,7 +7,7 @@ use crate::app::model::{account, prelude::Account}; use crate::shared::core::db; use crate::shared::crypto::hash; use crate::shared::result::code::Code; -use crate::shared::result::{status, ApiResult}; +use crate::shared::result::{reply, ApiResult}; use crate::shared::util::identity::Identity; use crate::shared::util::{helper, xtime}; @@ -73,7 +73,7 @@ pub async fn login(req: ReqLogin) -> ApiResult { auth_token, }; - Ok(status::OK(Some(resp))) + Ok(reply::OK(Some(resp))) } pub async fn logout(identity: &Identity) -> ApiResult<()> { @@ -92,5 +92,5 @@ pub async fn logout(identity: &Identity) -> ApiResult<()> { return Err(Code::ErrSystem(None)); } - Ok(status::OK(None)) + Ok(reply::OK(None)) } diff --git a/src/app/service/project.rs b/src/app/service/project.rs index 058ff0c..ddc6b4e 100644 --- a/src/app/service/project.rs +++ b/src/app/service/project.rs @@ -7,7 +7,7 @@ use validator::Validate; use crate::shared::core::db; use crate::shared::result::code::Code; -use crate::shared::result::{status, ApiResult}; +use crate::shared::result::{reply, ApiResult}; use crate::shared::util::identity::{Identity, Role}; use crate::shared::util::{helper, xtime}; @@ -52,7 +52,7 @@ pub async fn create(id: &Identity, req: ReqCreate) -> ApiResult<()> { return Err(Code::ErrSystem(None)); } - Ok(status::OK(None)) + Ok(reply::OK(None)) } #[derive(Debug, Serialize)] @@ -136,7 +136,7 @@ pub async fn list(id: &Identity, query: &MultiMap) -> ApiResult< resp.list.push(info); } - Ok(status::OK(Some(resp))) + Ok(reply::OK(Some(resp))) } #[derive(Debug, Serialize)] @@ -185,5 +185,5 @@ pub async fn detail(id: &Identity, project_id: u64) -> ApiResult { }) } - Ok(status::OK(Some(resp))) + Ok(reply::OK(Some(resp))) } diff --git a/src/shared/middleware/catch_panic.rs b/src/shared/middleware/catch_panic.rs index c110d66..dccae07 100644 --- a/src/shared/middleware/catch_panic.rs +++ b/src/shared/middleware/catch_panic.rs @@ -27,7 +27,7 @@ impl Handler for CatchPanic { .catch_unwind() .await { - resp.render(Json(Code::ErrSystem(None).to_status())); + resp.render(Json(Code::ErrSystem(None).to_reply())); } } } diff --git a/src/shared/middleware/log.rs b/src/shared/middleware/log.rs index d941939..7728ded 100644 --- a/src/shared/middleware/log.rs +++ b/src/shared/middleware/log.rs @@ -34,7 +34,7 @@ impl Handler for Log { // 获取body let (body, code) = drain_body(req).await; if let Some(v) = code { - resp.render(Json(v.to_status())); + resp.render(Json(v.to_reply())); ctrl.skip_rest(); return; } diff --git a/src/shared/middleware/trace.rs b/src/shared/middleware/trace.rs index 47fced5..b660397 100644 --- a/src/shared/middleware/trace.rs +++ b/src/shared/middleware/trace.rs @@ -5,7 +5,7 @@ use tracing::Instrument; use crate::shared::{crypto::hash, util::identity::Identity}; -pub const TRACE_ID: &str = "x-trace-id"; +pub const TRACE_ID: HeaderName = HeaderName::from_static("x-trace-id"); pub struct Trace; @@ -54,7 +54,7 @@ impl Handler for Trace { ctrl.call_next(req, depot, resp).instrument(span).await; // 设置返回header resp.headers_mut().insert( - HeaderName::from_static(TRACE_ID), + TRACE_ID, HeaderValue::from_str(&trace_id).unwrap_or(HeaderValue::from_static("")), ); } @@ -63,7 +63,7 @@ impl Handler for Trace { fn gen_trace_id(req: &mut Request, hostname: &str) -> String { let id = hash::md5(format!("{}/{}", hostname, nanoid!(32)).as_bytes()); req.headers_mut().insert( - HeaderName::from_static(TRACE_ID), + TRACE_ID, HeaderValue::from_str(&id).unwrap_or(HeaderValue::from_static("")), ); id diff --git a/src/shared/result/code.rs b/src/shared/result/code.rs index 9507321..998928c 100644 --- a/src/shared/result/code.rs +++ b/src/shared/result/code.rs @@ -1,7 +1,7 @@ use salvo::prelude::*; use salvo::{Depot, Request, Response, Writer}; -use super::status::Status; +use super::reply::Reply; pub enum Code { New(i32, String), @@ -15,7 +15,7 @@ pub enum Code { } impl Code { - pub fn to_status(self) -> Status<()> { + pub fn to_reply(self) -> Reply<()> { let (code, msg) = match self { Code::New(code, msg) => (code, msg), Code::ErrParams(msg) => (10000, msg.unwrap_or(String::from("参数错误"))), @@ -26,7 +26,7 @@ impl Code { Code::ErrData(msg) => (60000, msg.unwrap_or(String::from("数据异常"))), Code::ErrService(msg) => (70000, msg.unwrap_or(String::from("服务异常"))), }; - Status { + Reply { code, err: true, msg, @@ -38,6 +38,6 @@ impl Code { #[async_trait] impl Writer for Code { async fn write(mut self, _req: &mut Request, _depot: &mut Depot, resp: &mut Response) { - resp.render(Json(self.to_status())); + resp.render(Json(self.to_reply())); } } diff --git a/src/shared/result/mod.rs b/src/shared/result/mod.rs index 713a42c..8ecb168 100644 --- a/src/shared/result/mod.rs +++ b/src/shared/result/mod.rs @@ -1,4 +1,4 @@ pub mod code; -pub mod status; +pub mod reply; -pub type ApiResult = Result, code::Code>; +pub type ApiResult = Result, code::Code>; diff --git a/src/shared/result/status.rs b/src/shared/result/reply.rs similarity index 85% rename from src/shared/result/status.rs rename to src/shared/result/reply.rs index cdb6f47..6f856e9 100644 --- a/src/shared/result/status.rs +++ b/src/shared/result/reply.rs @@ -3,7 +3,7 @@ use salvo::{Depot, Request, Response, Writer}; use serde::Serialize; #[derive(Serialize)] -pub struct Status +pub struct Reply where T: Serialize, { @@ -22,8 +22,8 @@ impl OK where T: Serialize + std::marker::Send, { - pub fn to_status(self) -> Status { - Status { + pub fn to_reply(self) -> Reply { + Reply { code: 0, err: false, msg: String::from("OK"), @@ -38,6 +38,6 @@ where T: Serialize + std::marker::Send, { async fn write(mut self, _req: &mut Request, _depot: &mut Depot, resp: &mut Response) { - resp.render(Json(self.to_status())); + resp.render(Json(self.to_reply())); } } diff --git a/src/shared/util/identity.rs b/src/shared/util/identity.rs index 92fe6a0..ea2613d 100644 --- a/src/shared/util/identity.rs +++ b/src/shared/util/identity.rs @@ -37,6 +37,9 @@ impl Identity { } pub fn from_auth_token(token: String) -> Self { + if token.len() == 0 { + return Identity::empty(); + } let cipher = match BASE64_STANDARD.decode(token) { Err(e) => { tracing::error!(error = ?e, "error invalid auth_token");