diff --git a/Cargo.lock b/Cargo.lock index 20a40c2..327ef66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,9 +30,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", "getrandom", @@ -127,9 +127,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.77" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "api" @@ -138,7 +138,7 @@ dependencies = [ "anyhow", "axum", "axum-extra", - "base64 0.21.5", + "base64 0.21.6", "chrono", "config", "entity", @@ -196,18 +196,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] name = "async-trait" -version = "0.1.75" +version = "0.1.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdf6721fb0140e4f897002dd086c06f6c27775df19cfe1fccb21181a48fd2c98" +checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -237,9 +237,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "202651474fe73c62d9e0a56c6133f7a0ff1dc1c8cf7a5b03381af2a26553ac9d" +checksum = "d09dbe0e490df5da9d69b36dca48a76635288a82f92eca90024883a56202026d" dependencies = [ "async-trait", "axum-core", @@ -267,13 +267,14 @@ dependencies = [ "tower", "tower-layer", "tower-service", + "tracing", ] [[package]] name = "axum-core" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77cb22c689c44d4c07b0ab44ebc25d69d8ae601a2f28fb8d672d344178fa17aa" +checksum = "e87c8503f93e6d144ee5690907ba22db7ba79ab001a932ab99034f0fe836b3df" dependencies = [ "async-trait", "bytes", @@ -287,13 +288,14 @@ dependencies = [ "sync_wrapper", "tower-layer", "tower-service", + "tracing", ] [[package]] name = "axum-extra" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523ae92256049a3b02d3bb4df80152386cd97ddba0c8c5077619bdc8c4b1859b" +checksum = "881348a37b079994894b6e5e46edcc4b8a60e1c0333669a65b810abeed780598" dependencies = [ "axum", "axum-core", @@ -319,7 +321,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -345,9 +347,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.5" +version = "0.21.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "c79fed4cdb43e993fcdadc7e58a09fd0e3e649c4436fa11da71c9f1f3ee7feb9" [[package]] name = "base64ct" @@ -422,7 +424,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", "syn_derive", ] @@ -504,18 +506,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.11" +version = "4.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" +checksum = "33e92c5c1a78c62968ec57dbc2440366a2d6e5a23faf829970ff1585dc6b18e2" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.4.11" +version = "4.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" +checksum = "f4323769dc8a61e2c39ad7dc26f6f2800524691a44d74fe3d1071a5c24db6370" dependencies = [ "anstream", "anstyle", @@ -602,9 +604,9 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -632,32 +634,27 @@ checksum = "338089f42c427b86394a5ee60ff321da23a5c89c9d89514c829687b26359fcff" [[package]] name = "crossbeam-channel" -version = "0.5.10" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82a9b73a36529d9c47029b9fb3a6f0ea3cc916a261195352ba19e770fc1748b2" +checksum = "176dc175b78f56c0f321911d9c8eb2b77a78a4860b9c19db83835fea1a46649b" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-queue" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adc6598521bb5a83d491e8c1fe51db7296019d2ca3cb93cc6c2a20369a4d78a2" +checksum = "df0346b5d5e76ac2fe4e327c5fd1118d6be7c51dfb18f9b7922923f287471e35" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.18" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crypto-common" @@ -682,9 +679,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eb30d70a07a3b04884d2677f06bec33509dc67ca60d92949e5535352d3191dc" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", "serde", @@ -900,7 +897,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -945,9 +942,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", @@ -962,9 +959,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "h2" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d308f63daf4181410c242d34c11f928dcb3aa105852019e043c9d1f4e4368a" +checksum = "991910e35c615d8cab86b5ab04be67e6ad24d2bf5f4f11fdbbed26da999bbeab" dependencies = [ "bytes", "fnv", @@ -994,7 +991,7 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" dependencies = [ - "ahash 0.8.6", + "ahash 0.8.7", "allocator-api2", ] @@ -1140,9 +1137,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.58" +version = "0.1.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +checksum = "b6a67363e2aa4443928ce15e57ebae94fd8949958fd1223c4cfc0cd473ad7539" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1199,13 +1196,13 @@ dependencies = [ [[package]] name = "inherent" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce243b1bfa62ffc028f1cc3b6034ec63d649f3031bc8a4fbbb004e1ac17d1f68" +checksum = "0122b7114117e64a63ac49f752a5ca4624d534c7b1c7de796ac196381cd2d947" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -1254,9 +1251,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.151" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libm" @@ -1271,7 +1268,7 @@ dependencies = [ "anyhow", "axum", "axum-extra", - "base64 0.21.5", + "base64 0.21.6", "chrono", "config", "const-hex", @@ -1288,6 +1285,7 @@ dependencies = [ "sha1", "sha2", "thiserror", + "tokio", "tracing", "tracing-appender", "tracing-subscriber", @@ -1351,9 +1349,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "mime" @@ -1525,7 +1523,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -1580,7 +1578,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -1641,9 +1639,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pest" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae9cee2a55a544be8b89dc6848072af97a20f2422603c10865be2a42b580fff5" +checksum = "1f200d8d83c44a45b21764d1916299752ca035d15ecd46faca3e9a2a2bf6ad06" dependencies = [ "memchr", "thiserror", @@ -1652,9 +1650,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81d78524685f5ef2a3b3bd1cafbc9fcabb036253d9b1463e726a91cd16e2dfc2" +checksum = "bcd6ab1236bbdb3a49027e920e693192ebfe8913f6d60e294de57463a493cfde" dependencies = [ "pest", "pest_generator", @@ -1662,22 +1660,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68bd1206e71118b5356dae5ddc61c8b11e28b09ef6a31acbd15ea48a28e0c227" +checksum = "2a31940305ffc96863a735bef7c7994a00b325a7138fdbc5bda0f1a0476d3275" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] name = "pest_meta" -version = "2.7.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c747191d4ad9e4a4ab9c8798f1e82a39affe7ef9648390b7e5548d18e099de6" +checksum = "a7ff62f5259e53b78d1af898941cdcdccfae7385cf7d793a6e55de5d05bb4b7d" dependencies = [ "once_cell", "pest", @@ -1701,7 +1699,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -1791,9 +1789,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.71" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] @@ -1836,9 +1834,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -2096,7 +2094,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64 0.21.5", + "base64 0.21.6", ] [[package]] @@ -2147,7 +2145,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -2188,15 +2186,15 @@ dependencies = [ "proc-macro2", "quote", "sea-bae", - "syn 2.0.43", + "syn 2.0.48", "unicode-ident", ] [[package]] name = "sea-query" -version = "0.30.5" +version = "0.30.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e40446e3c048cec0802375f52462a05cc774b9ea6af1dffba6c646b7825e4cf9" +checksum = "a4a1feb0a26c02efedb049b22d3884e66f15a40c42b33dcbe49b46abc484c2bd" dependencies = [ "bigdecimal", "chrono", @@ -2233,29 +2231,29 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" dependencies = [ "itoa", "ryu", @@ -2264,9 +2262,9 @@ dependencies = [ [[package]] name = "serde_path_to_error" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4beec8bce849d58d06238cb50db2e1c417cfeafa4c63f692b15c82b7c80f8335" +checksum = "ebd154a240de39fdebcf5775d2675c204d7c13cf39a4c697be6493c8e734337c" dependencies = [ "itoa", "serde", @@ -2287,6 +2285,10 @@ dependencies = [ [[package]] name = "service" version = "0.1.0" +dependencies = [ + "entity", + "library", +] [[package]] name = "sha1" @@ -2440,7 +2442,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d84b0a3c3739e220d94b3239fd69fb1f74bc36e16643423bd99de3b43c21bfbd" dependencies = [ - "ahash 0.8.6", + "ahash 0.8.7", "atoi", "bigdecimal", "byteorder", @@ -2529,7 +2531,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e37195395df71fd068f6e2082247891bc11e3289624bbc776a0cdfa1ca7f1ea4" dependencies = [ "atoi", - "base64 0.21.5", + "base64 0.21.6", "bigdecimal", "bitflags 2.4.1", "byteorder", @@ -2576,7 +2578,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6ac0ac3b7ccd10cc96c7ab29791a7dd236bd94021f31eec7ba3d46a74aa1c24" dependencies = [ "atoi", - "base64 0.21.5", + "base64 0.21.6", "bigdecimal", "bitflags 2.4.1", "byteorder", @@ -2688,9 +2690,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.43" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -2706,7 +2708,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -2723,35 +2725,35 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.8.1" +version = "3.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ "cfg-if", "fastrand", "redox_syscall", "rustix", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "thiserror" -version = "1.0.52" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a48fd946b02c0a526b2e9481c8e2a17755e47039164a86c4070446e3a4614d" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.52" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7fbe9b594d6568a6a1443250a7e67d80b74e1e96f6d1715e1e21cc1888291d3" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -2835,7 +2837,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -2967,7 +2969,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] @@ -3203,7 +3205,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", "wasm-bindgen-shared", ] @@ -3225,7 +3227,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3272,11 +3274,11 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-core" -version = "0.51.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.48.5", + "windows-targets 0.52.0", ] [[package]] @@ -3413,9 +3415,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.30" +version = "0.5.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5" +checksum = "b7520bbdec7211caa7c4e682eb1fbe07abe20cee6756b6e00f537c82c11816aa" dependencies = [ "memchr", ] @@ -3455,7 +3457,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn 2.0.48", ] [[package]] diff --git a/Dockerfile b/Dockerfile index e1b3454..f3393d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.67 as builder +FROM rust:1.70 as builder WORKDIR /api_rs @@ -19,4 +19,4 @@ EXPOSE 8000 ENTRYPOINT ["./api_rs"] -CMD ["/data/config.yaml"] +CMD ["serve", "--config", "/data/config.yaml"] diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 0f7f6a5..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 shenghui0779 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/api/src/auth/identity.rs b/api/src/auth/identity.rs index 6db89e3..49a83cd 100644 --- a/api/src/auth/identity.rs +++ b/api/src/auth/identity.rs @@ -1,11 +1,13 @@ use anyhow::{anyhow, Result}; use base64::{prelude::BASE64_STANDARD, Engine}; -use config::Config; -use sea_orm::{DatabaseConnection, EntityTrait}; +use sea_orm::EntityTrait; use serde::{Deserialize, Serialize}; use entity::prelude::Account; -use library::crypto::aes::CBC; +use library::{ + core::{cfg, db}, + crypto::aes::CBC, +}; use super::Role; @@ -33,7 +35,7 @@ impl Identity { } } - pub fn from_auth_token(cfg: &Config, token: String) -> Self { + pub fn from_auth_token(token: String) -> Self { let cipher = match BASE64_STANDARD.decode(token) { Err(err) => { tracing::error!(error = ?err, "err invalid auth_token"); @@ -42,7 +44,7 @@ impl Identity { Ok(v) => v, }; - let secret = match cfg.get_string("app.secret") { + let secret = match cfg::config().get_string("app.secret") { Err(err) => { tracing::error!(error = ?err, "err missing config(app.secret)"); return Identity::empty(); @@ -68,8 +70,8 @@ impl Identity { } } - pub fn to_auth_token(&self, cfg: &Config) -> Result { - let secret = cfg.get_string("app.secret")?; + pub fn to_auth_token(&self) -> Result { + let secret = cfg::config().get_string("app.secret")?; let key = secret.as_bytes(); let plain = serde_json::to_vec(self)?; @@ -99,12 +101,12 @@ impl Identity { false } - pub async fn check(&self, db: &DatabaseConnection) -> Result<()> { + pub async fn check(&self) -> Result<()> { if self.id() == 0 { return Err(anyhow!("未授权,请先登录")); } - match Account::find_by_id(self.id()).one(db).await? { + match Account::find_by_id(self.id()).one(db::conn()).await? { None => return Err(anyhow!("授权账号不存在")), Some(v) => { if v.login_token.len() == 0 || self.t != v.login_token { diff --git a/api/src/auth/mod.rs b/api/src/auth/mod.rs index 4ed2d8a..5045a6d 100644 --- a/api/src/auth/mod.rs +++ b/api/src/auth/mod.rs @@ -1,6 +1,5 @@ pub mod identity; -#[allow(dead_code)] pub enum Role { Super, Normal, diff --git a/api/src/controller/account.rs b/api/src/controller/account.rs index ccbd56c..89f1ef8 100644 --- a/api/src/controller/account.rs +++ b/api/src/controller/account.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use axum::{ - extract::{Path, Query, State}, + extract::{Path, Query}, Extension, Json, }; use axum_extra::extract::WithRejection; @@ -12,7 +12,6 @@ use serde::{Deserialize, Serialize}; use validator::Validate; use entity::{account, prelude::*}; -use library::crypto::hash::md5; use library::result::{ rejection::IRejection, response::{ApiErr, ApiOK, Result}, @@ -21,11 +20,9 @@ use library::util::{ helper, time::{self, Layout}, }; +use library::{core::db, crypto::hash::md5}; -use crate::{ - auth::{identity::Identity, Role}, - AppState, -}; +use crate::auth::{identity::Identity, Role}; #[derive(Debug, Validate, Deserialize, Serialize)] pub struct ParamsCreate { @@ -38,7 +35,6 @@ pub struct ParamsCreate { } pub async fn create( - State(state): State, Extension(identity): Extension, WithRejection(Json(params), _): IRejection>, ) -> Result> { @@ -52,7 +48,7 @@ pub async fn create( match Account::find() .filter(account::Column::Username.eq(params.username.clone())) - .count(&state.db) + .count(db::conn()) .await { Err(err) => { @@ -82,7 +78,7 @@ pub async fn create( ..Default::default() }; - if let Err(err) = Account::insert(model).exec(&state.db).await { + if let Err(err) = Account::insert(model).exec(db::conn()).await { tracing::error!(error = ?err, "err insert account"); return Err(ApiErr::ErrSystem(None)); @@ -103,7 +99,6 @@ pub struct RespInfo { } pub async fn info( - State(state): State, Extension(identity): Extension, Path(account_id): Path, ) -> Result> { @@ -111,7 +106,7 @@ pub async fn info( return Err(ApiErr::ErrPerm(None)); } - let model = match Account::find_by_id(account_id).one(&state.db).await { + let model = match Account::find_by_id(account_id).one(db::conn()).await { Err(err) => { tracing::error!(error = ?err, "err find account"); return Err(ApiErr::ErrSystem(None)); @@ -142,7 +137,6 @@ pub struct RespList { } pub async fn list( - State(state): State, Extension(identity): Extension, Query(query): Query>, ) -> Result> { @@ -169,7 +163,7 @@ pub async fn list( .select_only() .column_as(account::Column::Id.count(), "count") .into_tuple::() - .one(&state.db) + .one(db::conn()) .await { Err(err) => { @@ -184,7 +178,7 @@ pub async fn list( .order_by(account::Column::Id, Order::Desc) .offset(offset) .limit(limit) - .all(&state.db) + .all(db::conn()) .await { Err(err) => { diff --git a/api/src/controller/auth.rs b/api/src/controller/auth.rs index 07b9bbd..529947f 100644 --- a/api/src/controller/auth.rs +++ b/api/src/controller/auth.rs @@ -1,6 +1,6 @@ -use axum::extract::State; use axum::{Extension, Json}; use axum_extra::extract::WithRejection; +use library::core::db; use sea_orm::sea_query::Expr; use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, Set}; use serde::{Deserialize, Serialize}; @@ -15,7 +15,6 @@ use library::result::{ use library::util::helper; use crate::auth::identity::Identity; -use crate::AppState; #[derive(Debug, Validate, Deserialize, Serialize)] pub struct ParamsLogin { @@ -33,7 +32,6 @@ pub struct RespLogin { } pub async fn login( - State(state): State, WithRejection(Json(params), _): IRejection>, ) -> Result> { if let Err(err) = params.validate() { @@ -42,7 +40,7 @@ pub async fn login( let ret = Account::find() .filter(account::Column::Username.eq(params.username)) - .one(&state.db) + .one(db::conn()) .await; let record = match ret { @@ -67,14 +65,14 @@ pub async fn login( let now = chrono::Local::now().timestamp(); let login_token = md5(format!("auth.{}.{}.{}", model.id, now, helper::nonce(16)).as_bytes()); - let auth_token = - match Identity::new(model.id, model.role, login_token.clone()).to_auth_token(&state.cfg) { - Err(err) => { - tracing::error!(error = ?err, "err identity encrypt"); - return Err(ApiErr::ErrSystem(None)); - } - Ok(v) => v, - }; + let auth_token = match Identity::new(model.id, model.role, login_token.clone()).to_auth_token() + { + Err(err) => { + tracing::error!(error = ?err, "err identity encrypt"); + return Err(ApiErr::ErrSystem(None)); + } + Ok(v) => v, + }; let am = account::ActiveModel { login_at: Set(now), @@ -86,7 +84,7 @@ pub async fn login( let ret_update = Account::update_many() .filter(account::Column::Id.eq(model.id)) .set(am) - .exec(&state.db) + .exec(db::conn()) .await; if let Err(err) = ret_update { @@ -103,10 +101,7 @@ pub async fn login( Ok(ApiOK(Some(resp))) } -pub async fn logout( - State(state): State, - Extension(identity): Extension, -) -> Result> { +pub async fn logout(Extension(identity): Extension) -> Result> { if identity.id() == 0 { return Ok(ApiOK(None)); } @@ -118,7 +113,7 @@ pub async fn logout( account::Column::CreatedAt, Expr::value(chrono::Local::now().timestamp()), ) - .exec(&state.db) + .exec(db::conn()) .await; if let Err(err) = ret { diff --git a/api/src/controller/project.rs b/api/src/controller/project.rs index a68e14a..7458a0e 100644 --- a/api/src/controller/project.rs +++ b/api/src/controller/project.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use axum::{ - extract::{Path, Query, State}, + extract::{Path, Query}, Extension, Json, }; use axum_extra::extract::WithRejection; @@ -12,20 +12,20 @@ use sea_orm::{ use serde::{Deserialize, Serialize}; use validator::Validate; -use library::result::{ - rejection::IRejection, - response::{ApiErr, ApiOK, Result}, -}; use library::util::{ helper, time::{self, Layout}, }; - -use crate::{ - auth::{identity::Identity, Role}, - AppState, +use library::{ + core::db, + result::{ + rejection::IRejection, + response::{ApiErr, ApiOK, Result}, + }, }; +use crate::auth::{identity::Identity, Role}; + #[derive(Debug, Validate, Deserialize, Serialize)] pub struct ParamsCreate { #[validate(length(min = 1, max = 8, message = "项目编号必填且长度最大为8"))] @@ -36,7 +36,6 @@ pub struct ParamsCreate { } pub async fn create( - State(state): State, Extension(identity): Extension, WithRejection(Json(params), _): IRejection>, ) -> Result> { @@ -47,7 +46,7 @@ pub async fn create( // 校验编号唯一性 match Project::find() .filter(project::Column::Code.eq(params.code.clone())) - .count(&state.db) + .count(db::conn()) .await { Err(err) => { @@ -73,7 +72,7 @@ pub async fn create( ..Default::default() }; - if let Err(err) = Project::insert(am).exec(&state.db).await { + if let Err(err) = Project::insert(am).exec(db::conn()).await { tracing::error!(error = ?err, "err insert project"); return Err(ApiErr::ErrSystem(None)); } @@ -97,7 +96,6 @@ pub struct RespList { } pub async fn list( - State(state): State, Extension(identity): Extension, Query(query): Query>, ) -> Result> { @@ -136,7 +134,7 @@ pub async fn list( .select_only() .column_as(project::Column::Id.count(), "count") .into_tuple::() - .one(&state.db) + .one(db::conn()) .await { Err(err) => { @@ -151,7 +149,7 @@ pub async fn list( .order_by(project::Column::Id, Order::Desc) .offset(offset) .limit(limit) - .all(&state.db) + .all(db::conn()) .await { Err(err) => { @@ -198,13 +196,12 @@ pub struct ProjAccount { } pub async fn detail( - State(state): State, Extension(identity): Extension, Path(project_id): Path, ) -> Result> { let (model_proj, model_account) = match Project::find_by_id(project_id) .find_also_related(Account) - .one(&state.db) + .one(db::conn()) .await { Err(err) => { diff --git a/api/src/lib.rs b/api/src/lib.rs index 5987a69..6101979 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -1,30 +1,13 @@ -use config::Config; -use redis::Client as RedisClient; -use sea_orm::DatabaseConnection; +use library::core::cfg; pub mod auth; pub mod controller; pub mod middleware; pub mod router; -#[derive(Debug, Clone)] -pub struct AppState { - pub cfg: Config, - pub db: DatabaseConnection, - pub redis: RedisClient, -} - -async fn app_state(cfg: Config) -> AppState { - let db = library::core::db::init(&cfg).await; - let redis = library::core::redis::init(&cfg); - - AppState { cfg, db, redis } -} - -pub async fn serve(cfg: Config) { +pub async fn serve() { // run it with hyper on localhost:8000 - let addr = cfg.get_int("app.port").unwrap_or(8000); - let state = app_state(cfg).await; + let addr = cfg::config().get_int("app.port").unwrap_or(8000); let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", addr)) .await @@ -32,7 +15,5 @@ pub async fn serve(cfg: Config) { tracing::info!("listening on {}", addr); - axum::serve(listener, router::app::init(state)) - .await - .unwrap(); + axum::serve(listener, router::app::init()).await.unwrap(); } diff --git a/api/src/middleware/auth.rs b/api/src/middleware/auth.rs index b5f6afd..5de3938 100644 --- a/api/src/middleware/auth.rs +++ b/api/src/middleware/auth.rs @@ -1,19 +1,19 @@ use axum::{ - extract::{Request, State}, + extract::Request, middleware::Next, response::{IntoResponse, Response}, }; use library::result::response::ApiErr; -use crate::{auth::identity::Identity, AppState}; +use crate::auth::identity::Identity; -pub async fn handle(State(state): State, request: Request, next: Next) -> Response { +pub async fn handle(request: Request, next: Next) -> Response { let identity = request.extensions().get::(); match identity { None => return ApiErr::ErrAuth(None).into_response(), - Some(v) => match v.check(&state.db).await { + Some(v) => match v.check().await { Ok(_) => (), Err(err) => return ApiErr::ErrAuth(Some(err.to_string())).into_response(), }, diff --git a/api/src/middleware/identity.rs b/api/src/middleware/identity.rs index 0439227..e2af93c 100644 --- a/api/src/middleware/identity.rs +++ b/api/src/middleware/identity.rs @@ -1,19 +1,15 @@ -use axum::{ - extract::{Request, State}, - middleware::Next, - response::Response, -}; +use axum::{extract::Request, middleware::Next, response::Response}; use http::header::AUTHORIZATION; -use crate::{auth::identity::Identity, AppState}; +use crate::auth::identity::Identity; -pub async fn handle(State(state): State, mut request: Request, next: Next) -> Response { +pub async fn handle(mut request: Request, next: Next) -> Response { let token = request.headers().get(AUTHORIZATION); let identity = match token { None => Identity::empty(), Some(v) => match v.to_str() { - Ok(v) => Identity::from_auth_token(&state.cfg, v.to_string()), + Ok(v) => Identity::from_auth_token(v.to_string()), Err(err) => { tracing::error!(error = ?err, "err get header(authorization)"); Identity::empty() diff --git a/api/src/router/app.rs b/api/src/router/app.rs index 5a02f8f..e5c0af9 100644 --- a/api/src/router/app.rs +++ b/api/src/router/app.rs @@ -8,10 +8,10 @@ use tower_http::trace::TraceLayer; use crate::{ controller::{account, auth, project}, - middleware, AppState, + middleware, }; -pub fn init(state: AppState) -> Router { +pub fn init() -> Router { // 开放 let open = Router::new().route("/login", post(auth::login)); @@ -22,19 +22,13 @@ pub fn init(state: AppState) -> Router { .route("/accounts/:account_id", get(account::info)) .route("/projects", get(project::list).post(project::create)) .route("/projects/:project_id", get(project::detail)) - .layer(axum::middleware::from_fn_with_state( - state.clone(), - middleware::auth::handle, - )); + .layer(axum::middleware::from_fn(middleware::auth::handle)); Router::new() .route("/", get(|| async { "☺ welcome to Rust app" })) .nest("/v1", open.merge(auth)) .layer(axum::middleware::from_fn(middleware::log::handle)) - .layer(axum::middleware::from_fn_with_state( - state.clone(), - middleware::identity::handle, - )) + .layer(axum::middleware::from_fn(middleware::identity::handle)) .layer(axum::middleware::from_fn(middleware::cors::handle)) .layer( TraceLayer::new_for_http().make_span_with(|request: &Request| { @@ -51,5 +45,4 @@ pub fn init(state: AppState) -> Router { }), ) .layer(axum::middleware::from_fn(middleware::req_id::handle)) - .with_state(state) } diff --git a/config.toml.example b/config.toml.example index 3a646f7..2a9cb78 100644 --- a/config.toml.example +++ b/config.toml.example @@ -6,11 +6,7 @@ secret = "3f4e25e75c08dbf60ad6533c50167ce3" [db] dsn = "mysql://root:xuyun@520@127.0.0.1:3306/demo_rs" -min_conns = 10 -max_conns = 20 -conn_timeout = 10 -idle_timeout = 300 -max_lifetime = 600 +options = { min_conns = 10, max_conns = 20, conn_timeout = 10, idle_timeout = 300, max_lifetime = 60 } [redis] dsn = "redis://127.0.0.1:6379/0" diff --git a/library/Cargo.toml b/library/Cargo.toml index d19f935..40951b0 100644 --- a/library/Cargo.toml +++ b/library/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +tokio = { version = "1", features = ["full"] } thiserror = "1.0" anyhow = "1.0" rand = "0.8" diff --git a/library/src/core/config.rs b/library/src/core/cfg.rs similarity index 51% rename from library/src/core/config.rs rename to library/src/core/cfg.rs index ee6e5f8..961dac8 100644 --- a/library/src/core/config.rs +++ b/library/src/core/cfg.rs @@ -1,12 +1,20 @@ use config::Config; -use std::fs; +use std::{fs, sync::OnceLock}; -pub fn init(cfg_file: &String) -> Config { +static CFG: OnceLock = OnceLock::new(); + +pub fn init(cfg_file: &String) { let path = fs::canonicalize(cfg_file) .unwrap_or_else(|e| panic!("配置文件加载失败:{} - {}", e, cfg_file)); - Config::builder() + let cfg = Config::builder() .add_source(config::File::with_name(path.to_str().unwrap())) .build() - .unwrap_or_else(|e| panic!("配置文件加载失败:{}", e)) + .unwrap_or_else(|e| panic!("配置文件加载失败:{}", e)); + + let _ = CFG.set(cfg); +} + +pub fn config() -> &'static Config { + CFG.get().unwrap_or_else(|| panic!("配置文件未初始化")) } diff --git a/library/src/core/db.rs b/library/src/core/db.rs index b89a0c8..08765b6 100644 --- a/library/src/core/db.rs +++ b/library/src/core/db.rs @@ -1,22 +1,23 @@ -use std::time::Duration; +use std::{sync::OnceLock, time::Duration}; use config::Config; use sea_orm::{ConnectOptions, Database, DatabaseConnection}; -#[allow(dead_code)] -pub async fn init(cfg: &Config) -> DatabaseConnection { +pub static DB: OnceLock = OnceLock::new(); + +pub async fn init(cfg: &Config) { let mut opt = ConnectOptions::new(cfg.get_string("db.dsn").expect("缺少DSN配置")); - opt.min_connections(cfg.get_int("db.min_conns").unwrap_or(10) as u32) - .max_connections(cfg.get_int("db.max_conns").unwrap_or(10) as u32) + opt.min_connections(cfg.get_int("db.options.min_conns").unwrap_or(10) as u32) + .max_connections(cfg.get_int("db.options.max_conns").unwrap_or(20) as u32) .connect_timeout(Duration::from_secs( - cfg.get_int("db.conn_timeout").unwrap_or(10) as u64, + cfg.get_int("db.options.conn_timeout").unwrap_or(10) as u64, )) .idle_timeout(Duration::from_secs( - cfg.get_int("db.idle_timeout").unwrap_or(300) as u64, + cfg.get_int("db.options.idle_timeout").unwrap_or(300) as u64, )) .max_lifetime(Duration::from_secs( - cfg.get_int("db.max_lifetime").unwrap_or(600) as u64, + cfg.get_int("db.options.max_lifetime").unwrap_or(600) as u64, )) .sqlx_logging(cfg.get_bool("app.debug").unwrap_or_default()); @@ -28,5 +29,9 @@ pub async fn init(cfg: &Config) -> DatabaseConnection { .await .is_err_and(|e| panic!("数据库连接失败:{}", e)); - conn + let _ = DB.set(conn); +} + +pub fn conn() -> &'static DatabaseConnection { + DB.get().unwrap_or_else(|| panic!("数据库连接未初始化")) } diff --git a/library/src/core/logger.rs b/library/src/core/logger.rs index 532f877..c65c853 100644 --- a/library/src/core/logger.rs +++ b/library/src/core/logger.rs @@ -14,7 +14,6 @@ impl FormatTime for LocalTimer { } } -#[allow(dead_code)] pub fn init(cfg: Option<&Config>) -> WorkerGuard { // 直接初始化,采用默认的Subscriber,默认只输出INFO、WARN、ERROR级别的日志 // tracing_subscriber::fmt::init(); diff --git a/library/src/core/mod.rs b/library/src/core/mod.rs index 88d2430..7b05432 100644 --- a/library/src/core/mod.rs +++ b/library/src/core/mod.rs @@ -1,4 +1,4 @@ -pub mod config; +pub mod cfg; pub mod db; pub mod logger; pub mod redis; diff --git a/library/src/core/redis.rs b/library/src/core/redis.rs index 86ff066..d561fa4 100644 --- a/library/src/core/redis.rs +++ b/library/src/core/redis.rs @@ -1,9 +1,11 @@ use config::Config; use redis::{cluster::ClusterClient, Client}; -use std::time::Duration; +use std::{sync::OnceLock, time::Duration}; -#[allow(dead_code)] -pub fn init(cfg: &Config) -> Client { +pub static REDIS: OnceLock = OnceLock::new(); +pub static REDIS_CLUSTER: OnceLock = OnceLock::new(); + +pub fn init(cfg: &Config) { let client = Client::open(cfg.get_string("redis.dsn").expect("缺少DSN配置")) .unwrap_or_else(|e| panic!("Redis连接失败:{}", e)); @@ -14,11 +16,10 @@ pub fn init(cfg: &Config) -> Client { .query::(&mut conn) .unwrap_or_else(|e| panic!("Redis连接失败:{}", e)); - client + let _ = REDIS.set(client); } -#[allow(dead_code)] -pub fn init_cluster(cfg: &Config) -> ClusterClient { +pub fn init_cluster(cfg: &Config) { let nodes = cfg .get_array("redis-cluster.nodes") .expect("缺少nodes配置") @@ -30,10 +31,20 @@ pub fn init_cluster(cfg: &Config) -> ClusterClient { let mut conn = client .get_connection() - .unwrap_or_else(|e| panic!("Redis连接失败:{}", e)); + .unwrap_or_else(|e| panic!("Redis集群连接失败:{}", e)); let _ = redis::cmd("PING") .query::(&mut conn) - .unwrap_or_else(|e| panic!("Redis连接失败:{}", e)); + .unwrap_or_else(|e| panic!("Redis集群连接失败:{}", e)); + + let _ = REDIS_CLUSTER.set(client); +} + +pub fn client() -> &'static Client { + REDIS.get().unwrap_or_else(|| panic!("Redis连接未初始化")) +} - client +pub fn cluster() -> &'static ClusterClient { + REDIS_CLUSTER + .get() + .unwrap_or_else(|| panic!("Redis集群未初始化")) } diff --git a/library/src/crypto/aes.rs b/library/src/crypto/aes.rs index 7d4eb3d..3ae3dcb 100644 --- a/library/src/crypto/aes.rs +++ b/library/src/crypto/aes.rs @@ -5,7 +5,6 @@ use openssl::symm::{decrypt_aead, encrypt_aead, Cipher, Crypter, Mode}; // CBC(key, iv) pub struct CBC<'a>(pub &'a [u8], pub &'a [u8]); -#[allow(dead_code)] impl<'a> CBC<'a> { fn cipher(&self) -> Result { let cipher = match self.0.len() { @@ -49,10 +48,8 @@ impl<'a> CBC<'a> { // AES-ECB pkcs#7 // ECB(key) -#[allow(dead_code)] pub struct ECB<'a>(pub &'a [u8]); -#[allow(dead_code)] impl<'a> ECB<'a> { fn cipher(&self) -> Result { let cipher = match self.0.len() { @@ -96,10 +93,8 @@ impl<'a> ECB<'a> { // AES-GCM // GCM(key, nonce) -> (cipher, tag) -#[allow(dead_code)] pub struct GCM<'a>(pub &'a [u8], pub &'a [u8]); -#[allow(dead_code)] impl<'a> GCM<'a> { fn cipher(&self) -> Result { let cipher = match self.0.len() { diff --git a/library/src/crypto/hash.rs b/library/src/crypto/hash.rs index b4b103a..0e93224 100644 --- a/library/src/crypto/hash.rs +++ b/library/src/crypto/hash.rs @@ -4,42 +4,36 @@ use md5::Md5; use sha1::Sha1; use sha2::Sha256; -#[allow(dead_code)] pub fn md5(b: &[u8]) -> String { let mut h = Md5::new(); h.update(b); const_hex::encode(h.finalize()) } -#[allow(dead_code)] pub fn sha1(b: &[u8]) -> String { let mut h = Sha1::new(); h.update(b); const_hex::encode(h.finalize()) } -#[allow(dead_code)] pub fn sha256(b: &[u8]) -> String { let mut h = Sha256::new(); h.update(b); const_hex::encode(h.finalize()) } -#[allow(dead_code)] pub fn hash(b: &[u8]) -> String { let mut h = D::new(); h.update(b); const_hex::encode(h.finalize()) } -#[allow(dead_code)] pub fn hmac_sha256(key: &[u8], b: &[u8]) -> String { let mut h = Hmac::::new_from_slice(key).unwrap(); h.update(b); const_hex::encode(h.finalize().into_bytes()) } -#[allow(dead_code)] pub fn hmac(key: &[u8], b: &[u8]) -> String { let mut h = SimpleHmac::::new_from_slice(key).unwrap(); h.update(b); diff --git a/library/src/result/response.rs b/library/src/result/response.rs index 385413b..fb97be3 100644 --- a/library/src/result/response.rs +++ b/library/src/result/response.rs @@ -22,7 +22,6 @@ where } } -#[allow(dead_code)] pub enum ApiErr { Error(i32, String), ErrParams(Option), diff --git a/library/src/util/helper.rs b/library/src/util/helper.rs index cd45d76..e5d9657 100644 --- a/library/src/util/helper.rs +++ b/library/src/util/helper.rs @@ -34,7 +34,6 @@ pub fn query_page(args: &HashMap) -> (u64, u64) { (offset, limit) } -#[allow(dead_code)] pub fn new_validation_err(s: String) -> ValidationError { return ValidationError { code: Cow::from(""), diff --git a/library/src/util/mod.rs b/library/src/util/mod.rs index 71dd40c..171cf75 100644 --- a/library/src/util/mod.rs +++ b/library/src/util/mod.rs @@ -1,2 +1,3 @@ pub mod helper; +pub mod mutex; pub mod time; diff --git a/library/src/util/mutex.rs b/library/src/util/mutex.rs index 2b8440b..e8fec84 100644 --- a/library/src/util/mutex.rs +++ b/library/src/util/mutex.rs @@ -1,6 +1,5 @@ use redis::{AsyncCommands, Commands, ExistenceCheck::NX, SetExpiry::PX, SetOptions}; -#[allow(dead_code)] // 基于Redis的分布式锁 pub struct Distributed<'a> { cli: &'a redis::Client, @@ -9,7 +8,6 @@ pub struct Distributed<'a> { expire: usize, } -#[allow(dead_code)] impl<'a> Distributed<'a> { pub fn new( cli: &redis::Client, @@ -52,7 +50,6 @@ impl<'a> Distributed<'a> { } } -#[allow(dead_code)] impl<'a> Drop for Distributed<'a> { fn drop(&mut self) { let mut conn = match self.cli.get_connection() { diff --git a/library/src/util/time.rs b/library/src/util/time.rs index 15e9673..c86d57b 100644 --- a/library/src/util/time.rs +++ b/library/src/util/time.rs @@ -1,6 +1,5 @@ use chrono::prelude::*; -#[allow(dead_code)] pub enum Layout<'a> { Date(Option<&'a str>), Time(Option<&'a str>), @@ -20,7 +19,6 @@ impl<'a> Layout<'a> { pub struct Format<'a>(pub Layout<'a>); -#[allow(dead_code)] impl<'a> Format<'a> { // Unix时间戳格式化 pub fn to_string(self, timestamp: i64) -> String { diff --git a/service/Cargo.toml b/service/Cargo.toml index b3b38d7..19e144d 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -6,3 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +# workspace modules +library = { path = "../library" } +entity = { path = "../entity" } diff --git a/src/main.rs b/src/main.rs index 33f1227..20f2e0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use library::core::{config, logger}; +use library::core::{cfg, db, logger}; #[tokio::main] async fn main() { @@ -8,10 +8,15 @@ async fn main() { match matches.subcommand() { // Command: serve Some((cmd::serve::NAME, sub_matches)) => { - let cfg = config::init(sub_matches.get_one::(cmd::serve::ARG_FILE).unwrap()); - let _guard = logger::init(Some(&cfg)); + // 初始化配置 + cfg::init(sub_matches.get_one::(cmd::serve::ARG_FILE).unwrap()); + // 初始化日志 + let _guard = logger::init(Some(cfg::config())); + // 初始化数据库 + db::init(cfg::config()).await; - api::serve(cfg).await; + // 启动服务 + api::serve().await; } // Command: hello Some((cmd::hello::NAME, _sub_matches)) => println!("hello world"),