diff --git a/Cargo.lock b/Cargo.lock index 45ed006..108476c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,7 +70,7 @@ version = "1.0.0" dependencies = [ "actix-web", "casbin", - "loge", + "env_logger", "tokio 1.26.0", ] @@ -788,23 +788,30 @@ checksum = "71938f30533e4d95a6d17aa530939da3842c2ab6f4f84b9dae68447e4129f74a" [[package]] name = "askama" -version = "0.11.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb98f10f371286b177db5eeb9a6e5396609555686a35e1d4f7b9a9c6d8af0139" +checksum = "47cbc3cf73fa8d9833727bbee4835ba5c421a0d65b72daf9a7b5d0e0f9cfb57e" dependencies = [ "askama_derive", "askama_escape", - "askama_shared", + "humansize", + "num-traits", + "percent-encoding", ] [[package]] name = "askama_derive" -version = "0.11.2" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87bf87e6e8b47264efa9bde63d6225c6276a52e05e91bf37eaa8afd0032d6b71" +checksum = "e80b5ad1afe82872b7aa3e9de9b206ecb85584aa324f0f60fa4c903ce935936b" dependencies = [ - "askama_shared", + "basic-toml", + "mime", + "mime_guess", + "nom", "proc-macro2", + "quote", + "serde", "syn", ] @@ -814,26 +821,6 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" -[[package]] -name = "askama_shared" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf722b94118a07fcbc6640190f247334027685d4e218b794dbfe17c32bf38ed0" -dependencies = [ - "askama_escape", - "humansize", - "mime", - "mime_guess", - "nom", - "num-traits", - "percent-encoding", - "proc-macro2", - "quote", - "serde", - "syn", - "toml", -] - [[package]] name = "assert-json-diff" version = "1.1.0" @@ -1019,26 +1006,6 @@ dependencies = [ "tokio-postgres", ] -[[package]] -name = "atoi" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c57d12312ff59c811c0643f4d80830505833c9ffaebd193d819392b265be8e" -dependencies = [ - "num-traits", -] - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi 0.3.9", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -1532,6 +1499,15 @@ dependencies = [ "vsimd", ] +[[package]] +name = "basic-toml" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c0de75129aa8d0cceaf750b89013f0e08804d6ec61416da787b35ad0d7cddf1" +dependencies = [ + "serde", +] + [[package]] name = "basics" version = "1.0.0" @@ -1881,24 +1857,24 @@ dependencies = [ [[package]] name = "chrono-tz" -version = "0.6.3" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c39203181991a7dd4343b8005bd804e7a9a37afb8ac070e43771e8c820bbde" +checksum = "58549f1842da3080ce63002102d5bc954c7bc843d4f47818e642abdc36253552" dependencies = [ "chrono", "chrono-tz-build", - "phf 0.11.1", + "phf 0.10.1", ] [[package]] name = "chrono-tz-build" -version = "0.0.3" +version = "0.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f509c3a87b33437b05e2458750a0700e5bdd6956176773e6c7d6dd15a283a0c" +checksum = "db058d493fb2f65f41861bfed7e3fe6335264a9f0f92710cab5bdf01fef09069" dependencies = [ "parse-zoneinfo", - "phf 0.11.1", - "phf_codegen 0.11.1", + "phf 0.10.1", + "phf_codegen", ] [[package]] @@ -1993,17 +1969,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "colored" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" -dependencies = [ - "atty", - "lazy_static", - "winapi 0.3.9", -] - [[package]] name = "combine" version = "3.8.1" @@ -2198,21 +2163,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crc" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" -dependencies = [ - "crc-catalog", -] - -[[package]] -name = "crc-catalog" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" - [[package]] name = "crc32c" version = "0.6.3" @@ -2742,12 +2692,6 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" -[[package]] -name = "dotenvy" -version = "0.15.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03d8c417d7a8cb362e0c37e5d815f5eb7c37f79ff93707329d5a194e42e54ca0" - [[package]] name = "dtoa" version = "1.0.6" @@ -2759,9 +2703,6 @@ name = "either" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" -dependencies = [ - "serde", -] [[package]] name = "encoding_rs" @@ -2990,9 +2931,6 @@ version = "0.10.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" dependencies = [ - "futures-core", - "futures-sink", - "pin-project", "spin 0.9.6", ] @@ -3198,17 +3136,6 @@ dependencies = [ "futures-util", ] -[[package]] -name = "futures-intrusive" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a604f7a68fbf8103337523b1fadc8ade7361ee3f112f7c680ad179651616aed5" -dependencies = [ - "futures-core", - "lock_api 0.4.9", - "parking_lot 0.11.2", -] - [[package]] name = "futures-io" version = "0.3.27" @@ -3435,23 +3362,11 @@ dependencies = [ "hashbrown 0.11.2", ] -[[package]] -name = "hashlink" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69fe1fcf8b4278d860ad0548329f892a3631fb63f82574df68275f34cdbe0ffa" -dependencies = [ - "hashbrown 0.12.3", -] - [[package]] name = "heck" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -dependencies = [ - "unicode-segmentation", -] [[package]] name = "hello-world" @@ -3459,15 +3374,7 @@ version = "1.0.0" dependencies = [ "actix-web", "env_logger", -] - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", + "log", ] [[package]] @@ -3603,9 +3510,12 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "humansize" -version = "1.1.1" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" +checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" +dependencies = [ + "libm", +] [[package]] name = "humantime" @@ -4237,13 +4147,18 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "libm" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" + [[package]] name = "libsqlite3-sys" version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14" dependencies = [ - "cc", "pkg-config", "vcpkg", ] @@ -4326,19 +4241,6 @@ dependencies = [ "cfg-if 1.0.0", ] -[[package]] -name = "loge" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc44e963910d60dbd093f090cb56c6cec463f5b23c07a130097deef8fe854c4b" -dependencies = [ - "atty", - "chrono", - "colored", - "log", - "winapi 0.3.9", -] - [[package]] name = "lru" version = "0.8.1" @@ -4371,7 +4273,7 @@ checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016" dependencies = [ "log", "phf 0.10.1", - "phf_codegen 0.10.0", + "phf_codegen", "string_cache", "string_cache_codegen", "tendril", @@ -4448,7 +4350,7 @@ dependencies = [ "actix-web", "actix-web-lab", "aes-gcm-siv", - "base64 0.20.0", + "base64 0.21.0", "env_logger", "futures-util", "log", @@ -4510,9 +4412,9 @@ dependencies = [ [[package]] name = "minijinja" -version = "0.28.0" +version = "0.30.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea571551ee271bbed113dc8e82fce0131a0c80f2f7656c31e0e47594339d4037" +checksum = "650266e616c4634fd6c188a410886e8700689fe78197f54d194a9ed560863f94" dependencies = [ "memo-map", "self_cell", @@ -4521,9 +4423,9 @@ dependencies = [ [[package]] name = "minijinja-autoreload" -version = "0.28.0" +version = "0.30.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "522076c0a122672d46a1b96c9c56cb36e6b6b72222f5246ffe0a2eb5f9a0093e" +checksum = "9c53f321aea5d295c51d53ed6654a25256f2feed430664790d6dd46f90e8cd84" dependencies = [ "minijinja", "notify", @@ -4930,15 +4832,6 @@ dependencies = [ "reqwest 0.11.14", ] -[[package]] -name = "openssl-example" -version = "1.0.0" -dependencies = [ - "actix-web", - "env_logger", - "openssl", -] - [[package]] name = "openssl-macros" version = "0.1.0" @@ -5199,20 +5092,10 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" dependencies = [ - "phf_generator 0.10.0", + "phf_generator", "phf_shared 0.10.0", ] -[[package]] -name = "phf_codegen" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56ac890c5e3ca598bbdeaa99964edb5b0258a583a9eb6ef4e89fc85d9224770" -dependencies = [ - "phf_generator 0.11.1", - "phf_shared 0.11.1", -] - [[package]] name = "phf_generator" version = "0.10.0" @@ -5223,16 +5106,6 @@ dependencies = [ "rand 0.8.5", ] -[[package]] -name = "phf_generator" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf" -dependencies = [ - "phf_shared 0.11.1", - "rand 0.8.5", -] - [[package]] name = "phf_shared" version = "0.10.0" @@ -5240,6 +5113,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" dependencies = [ "siphasher", + "uncased", ] [[package]] @@ -5249,7 +5123,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1fb5f6f826b772a8d4c0394209441e7d37cbbb967ae9c7e0e8134365c9ee676" dependencies = [ "siphasher", - "uncased", ] [[package]] @@ -5952,7 +5825,7 @@ dependencies = [ "bitflags", "fallible-iterator", "fallible-streaming-iterator", - "hashlink 0.7.0", + "hashlink", "libsqlite3-sys", "memchr", "smallvec 1.10.0", @@ -6131,9 +6004,9 @@ checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" [[package]] name = "sailfish" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79aef0b4612749106d372dfdeee715082f2f0fe24263be08e19db9b00b694bf9" +checksum = "dd1369644089e936dea5df0d6201636e2b6eb2e9ad098efb2eca5606ece3fab7" dependencies = [ "itoap", "ryu", @@ -6143,9 +6016,9 @@ dependencies = [ [[package]] name = "sailfish-compiler" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "787ef14715822299715d98d6eb6157f03a57a5258ffbd3321847f7450853dd64" +checksum = "761019f0de360c654d51e068f07acfa8677e9566391ca290e1ab7c53a55d8d02" dependencies = [ "filetime", "home", @@ -6159,9 +6032,9 @@ dependencies = [ [[package]] name = "sailfish-macros" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0d39ce164c9e19147bcc4fa9ce9dcfc0a451e6cd0a996bb896fc7dee92887a4" +checksum = "dad9a1a51d085aa939115cf537c71b1e438de7d27363a039ce525bf393262303" dependencies = [ "proc-macro2", "sailfish-compiler", @@ -6502,6 +6375,7 @@ dependencies = [ "diesel", "dotenv", "env_logger", + "log", "once_cell", "r2d2", "rust-argon2", @@ -6637,107 +6511,6 @@ dependencies = [ "lock_api 0.4.9", ] -[[package]] -name = "sqlformat" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c12bc9199d1db8234678b7051747c07f517cdcf019262d1847b94ec8b1aee3e" -dependencies = [ - "itertools", - "nom", - "unicode_categories", -] - -[[package]] -name = "sqlx" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9249290c05928352f71c077cc44a464d880c63f26f7534728cca008e135c0428" -dependencies = [ - "sqlx-core", - "sqlx-macros", -] - -[[package]] -name = "sqlx-core" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcbc16ddba161afc99e14d1713a453747a2b07fc097d2009f4c300ec99286105" -dependencies = [ - "ahash 0.7.6", - "atoi", - "bitflags", - "byteorder", - "bytes 1.4.0", - "crc", - "crossbeam-queue 0.3.8", - "dotenvy", - "either", - "event-listener", - "flume", - "futures-channel", - "futures-core", - "futures-executor", - "futures-intrusive", - "futures-util", - "hashlink 0.8.1", - "hex", - "indexmap", - "itoa 1.0.6", - "libc", - "libsqlite3-sys", - "log", - "memchr", - "once_cell", - "paste", - "percent-encoding", - "rustls 0.20.8", - "rustls-pemfile", - "serde", - "sha2", - "smallvec 1.10.0", - "sqlformat", - "sqlx-rt", - "stringprep", - "thiserror", - "tokio-stream", - "url", - "webpki-roots 0.22.6", -] - -[[package]] -name = "sqlx-macros" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b850fa514dc11f2ee85be9d055c512aa866746adfacd1cb42d867d68e6a5b0d9" -dependencies = [ - "dotenvy", - "either", - "heck", - "hex", - "once_cell", - "proc-macro2", - "quote", - "serde", - "serde_json", - "sha2", - "sqlx-core", - "sqlx-rt", - "syn", - "url", -] - -[[package]] -name = "sqlx-rt" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24c5b2d25fa654cc5f841750b8e1cdedbe21189bf9a9382ee90bfa9dd3562396" -dependencies = [ - "once_cell", - "tokio 1.26.0", - "tokio-rustls", -] - [[package]] name = "standback" version = "0.2.17" @@ -6753,6 +6526,7 @@ version = "1.0.0" dependencies = [ "actix-web", "env_logger", + "log", ] [[package]] @@ -6840,7 +6614,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" dependencies = [ - "phf_generator 0.10.0", + "phf_generator", "phf_shared 0.10.0", "proc-macro2", "quote", @@ -6941,8 +6715,10 @@ name = "templating-askama" version = "1.0.0" dependencies = [ "actix-web", + "actix-web-lab", "askama", "env_logger", + "log", ] [[package]] @@ -6997,6 +6773,7 @@ dependencies = [ "actix-web", "actix-web-lab", "env_logger", + "log", "tera", ] @@ -7006,6 +6783,7 @@ version = "1.0.0" dependencies = [ "actix-web", "env_logger", + "log", "serde_json", "tinytemplate", ] @@ -7017,6 +6795,7 @@ dependencies = [ "actix-web", "derive_more", "env_logger", + "log", "yarte", "yarte_helpers", ] @@ -7034,9 +6813,9 @@ dependencies = [ [[package]] name = "tera" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df578c295f9ec044ff1c829daf31bb7581d5b3c2a7a3d87419afe1f2531438c" +checksum = "27df4164dd125228af4c90c9799a29740e39151767d579f3fc711491054a0378" dependencies = [ "chrono", "chrono-tz", @@ -7051,6 +6830,7 @@ dependencies = [ "serde", "serde_json", "slug", + "thread_local", "unic-segment", ] @@ -7085,11 +6865,10 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.1.7" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" dependencies = [ - "cfg-if 1.0.0", "once_cell", ] @@ -7213,20 +6992,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] -name = "todo" +name = "tls-openssl" version = "1.0.0" dependencies = [ - "actix-files", - "actix-session", "actix-web", - "actix-web-lab", - "dotenv", "env_logger", "log", - "serde", - "serde_json", - "sqlx", - "tera", + "openssl", ] [[package]] @@ -7912,12 +7684,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - [[package]] name = "unicode-width" version = "0.1.10" @@ -7930,12 +7696,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "unicode_categories" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" - [[package]] name = "universal-hash" version = "0.5.0" @@ -7952,6 +7712,7 @@ version = "1.0.0" dependencies = [ "actix-web", "env_logger", + "log", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 19cfee1..80b36e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = [ "basics/nested-routing", "basics/state", "basics/static-files", - "basics/todo", + # "basics/todo", "cors/backend", "data-factory", "databases/diesel", diff --git a/auth/casbin/Cargo.toml b/auth/casbin/Cargo.toml index adf8ba2..15dfb33 100644 --- a/auth/casbin/Cargo.toml +++ b/auth/casbin/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] actix-web.workspace = true + casbin = "2" -loge = { version = "0.4", default-features = false, features = ["colored", "chrono"] } -tokio = { workspace = true, features = ["sync"] } +env_logger.workspace = true +tokio.workspace = true diff --git a/auth/casbin/src/main.rs b/auth/casbin/src/main.rs index 47a5aff..ae2ad0c 100644 --- a/auth/casbin/src/main.rs +++ b/auth/casbin/src/main.rs @@ -23,10 +23,7 @@ async fn fail(enforcer: web::Data>, req: HttpRequest) -> HttpRe #[actix_web::main] async fn main() -> io::Result<()> { - std::env::set_var("RUST_LOG", "info"); - std::env::set_var("LOGE_FORMAT", "target"); - - loge::init(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); let model = DefaultModel::from_file("rbac/rbac_model.conf") .await diff --git a/auth/cookie-session/src/main.rs b/auth/cookie-session/src/main.rs index 96d4e7e..3bcd665 100644 --- a/auth/cookie-session/src/main.rs +++ b/auth/cookie-session/src/main.rs @@ -33,9 +33,9 @@ async fn index(session: Session, req: HttpRequest) -> Result<&'static str> { #[actix_web::main] async fn main() -> std::io::Result<()> { - std::env::set_var("RUST_LOG", "info"); - env_logger::init(); - log::info!("Starting http server: 127.0.0.1:8080"); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); + + log::info!("starting HTTP server at http://localhost:8080"); HttpServer::new(|| { App::new() diff --git a/auth/simple-auth-server/Cargo.toml b/auth/simple-auth-server/Cargo.toml index 291e7f1..6f99be7 100644 --- a/auth/simple-auth-server/Cargo.toml +++ b/auth/simple-auth-server/Cargo.toml @@ -4,20 +4,21 @@ version = "1.0.0" edition = "2021" [dependencies] -actix-web.workspace = true actix-identity.workspace = true actix-session = { workspace = true, features = ["cookie-session"] } +actix-web.workspace = true chrono = { version = "0.4.20", features = ["serde"] } derive_more.workspace = true diesel = { version = "2", features = ["postgres", "r2d2", "uuid", "chrono"] } dotenv = "0.15" env_logger.workspace = true +log = "0.4" once_cell = "1" r2d2 = "0.8" rust-argon2 = "1" -serde.workspace = true serde_json.workspace = true +serde.workspace = true sparkpost = "0.5" -uuid = { version = "1", features = ["v4", "serde"] } time = "0.3" +uuid = { version = "1", features = ["v4", "serde"] } diff --git a/auth/simple-auth-server/src/main.rs b/auth/simple-auth-server/src/main.rs index 34ad025..53d0e42 100644 --- a/auth/simple-auth-server/src/main.rs +++ b/auth/simple-auth-server/src/main.rs @@ -4,10 +4,7 @@ extern crate diesel; use actix_identity::IdentityMiddleware; use actix_session::{config::PersistentSession, storage::CookieSessionStore, SessionMiddleware}; use actix_web::{cookie::Key, middleware, web, App, HttpServer}; -use diesel::{ - prelude::*, - r2d2::{self, ConnectionManager}, -}; +use diesel::{prelude::*, r2d2}; use time::Duration; mod auth_handler; @@ -22,21 +19,19 @@ mod utils; #[actix_web::main] async fn main() -> std::io::Result<()> { dotenv::dotenv().ok(); - std::env::set_var( - "RUST_LOG", - "simple-auth-server=debug,actix_web=info,actix_server=info", - ); - env_logger::init(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); + let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set"); // create db connection pool - let manager = ConnectionManager::::new(database_url); + let manager = r2d2::ConnectionManager::::new(database_url); let pool: models::Pool = r2d2::Pool::builder() .build(manager) .expect("Failed to create pool."); let domain: String = std::env::var("DOMAIN").unwrap_or_else(|_| "localhost".to_string()); - // Start http server + log::info!("starting HTTP server at http://localhost:8080"); + HttpServer::new(move || { App::new() .app_data(web::Data::new(pool.clone())) diff --git a/basics/hello-world/Cargo.toml b/basics/hello-world/Cargo.toml index ad8fb79..af2c23e 100644 --- a/basics/hello-world/Cargo.toml +++ b/basics/hello-world/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" [dependencies] actix-web.workspace = true env_logger.workspace = true +log.workspace = true diff --git a/basics/hello-world/src/main.rs b/basics/hello-world/src/main.rs index e3f6514..98229e9 100644 --- a/basics/hello-world/src/main.rs +++ b/basics/hello-world/src/main.rs @@ -7,8 +7,9 @@ async fn index(req: HttpRequest) -> &'static str { #[actix_web::main] async fn main() -> std::io::Result<()> { - std::env::set_var("RUST_LOG", "actix_web=info"); - env_logger::init(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); + + log::info!("starting HTTP server at http://localhost:8080"); HttpServer::new(|| { App::new() diff --git a/basics/state/Cargo.toml b/basics/state/Cargo.toml index 57aaa18..a894b02 100644 --- a/basics/state/Cargo.toml +++ b/basics/state/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" [dependencies] actix-web.workspace = true env_logger.workspace = true +log.workspace = true diff --git a/basics/state/src/main.rs b/basics/state/src/main.rs index 3b90681..403af72 100644 --- a/basics/state/src/main.rs +++ b/basics/state/src/main.rs @@ -58,14 +58,15 @@ async fn index( #[actix_web::main] async fn main() -> io::Result<()> { - std::env::set_var("RUST_LOG", "actix_web=info"); - env_logger::init(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); // Create some global state prior to building the server #[allow(clippy::mutex_atomic)] // it's intentional. let counter_mutex = Data::new(Mutex::new(0usize)); let counter_atomic = Data::new(AtomicUsize::new(0usize)); + log::info!("starting HTTP server at http://localhost:8080"); + // move is necessary to give closure below ownership of counter1 HttpServer::new(move || { // Create some thread-local state diff --git a/https-tls/openssl/Cargo.toml b/https-tls/openssl/Cargo.toml index 6cfba17..b6a00f7 100644 --- a/https-tls/openssl/Cargo.toml +++ b/https-tls/openssl/Cargo.toml @@ -1,9 +1,10 @@ [package] -name = "openssl-example" +name = "tls-openssl" version = "1.0.0" edition = "2021" [dependencies] actix-web = { workspace = true, features = ["openssl"] } env_logger.workspace = true +log.workspace = true openssl = "0.10" diff --git a/https-tls/openssl/src/main.rs b/https-tls/openssl/src/main.rs index e7388b6..2a9bd76 100644 --- a/https-tls/openssl/src/main.rs +++ b/https-tls/openssl/src/main.rs @@ -13,10 +13,7 @@ async fn index(req: HttpRequest) -> Result { #[actix_web::main] async fn main() -> io::Result<()> { - std::env::set_var("RUST_LOG", "actix_web=debug"); - env_logger::init(); - - println!("Started http server: https://127.0.0.1:8443"); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); // load TLS keys let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap(); @@ -25,6 +22,8 @@ async fn main() -> io::Result<()> { .unwrap(); builder.set_certificate_chain_file("cert.pem").unwrap(); + log::info!("starting HTTPS server at http://localhost:8443"); + HttpServer::new(|| { App::new() // enable logger diff --git a/json/jsonrpc/src/main.rs b/json/jsonrpc/src/main.rs index f4ad7ec..7ef875b 100644 --- a/json/jsonrpc/src/main.rs +++ b/json/jsonrpc/src/main.rs @@ -139,11 +139,12 @@ impl AppState { #[actix_web::main] async fn main() -> std::io::Result<()> { - std::env::set_var("RUST_LOG", "info"); - env_logger::init(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); let network = Arc::new(RwLock::new(ObjNetwork::new())); + log::info!("starting HTTP server at http://localhost:8080"); + HttpServer::new(move || { let app_state = AppState::new(network.clone()); App::new() diff --git a/middleware/middleware-encrypted-payloads/Cargo.toml b/middleware/middleware-encrypted-payloads/Cargo.toml index 08eb2b0..3312440 100644 --- a/middleware/middleware-encrypted-payloads/Cargo.toml +++ b/middleware/middleware-encrypted-payloads/Cargo.toml @@ -9,7 +9,7 @@ actix-web.workspace = true actix-web-lab.workspace = true aes-gcm-siv = "0.11" -base64 = "0.20" +base64 = "0.21" env_logger.workspace = true futures-util.workspace = true log.workspace = true diff --git a/middleware/middleware-encrypted-payloads/README.md b/middleware/middleware-encrypted-payloads/README.md index 8a27273..341d0dd 100644 --- a/middleware/middleware-encrypted-payloads/README.md +++ b/middleware/middleware-encrypted-payloads/README.md @@ -14,10 +14,11 @@ All this to say, it provides a (fairly brittle) way to have handlers not need to ## Usage +Using [HTTPie] throughout for simplicity. + ```console $ http POST :8080/encrypt id:=1234 data=abcde > tmp.json -POST /reverse HTTP/1.1 -Content-Length: 76 +HTTP/1.1 200 OK Content-Type: application/json { @@ -28,7 +29,6 @@ Content-Type: application/json $ cat tmp.json | http -v POST :8080/reverse HTTP/1.1 200 OK -Content-Length: 66 Content-Type: application/json { @@ -49,3 +49,5 @@ The server logs would look something like [INFO middleware_encrypted_payloads] encrypting response 1234 [INFO actix_web::middleware::logger] 127.0.0.1 "POST /reverse HTTP/1.1" 200 66 "-" "-" 0.000425 ``` + +[httpie]: https://httpie.io/cli diff --git a/middleware/middleware-encrypted-payloads/src/main.rs b/middleware/middleware-encrypted-payloads/src/main.rs index b1438be..da4d510 100644 --- a/middleware/middleware-encrypted-payloads/src/main.rs +++ b/middleware/middleware-encrypted-payloads/src/main.rs @@ -7,6 +7,7 @@ use actix_web::{ }; use actix_web_lab::middleware::{from_fn, Next}; use aes_gcm_siv::{aead::Aead as _, Aes256GcmSiv, KeyInit as _, Nonce}; +use base64::prelude::*; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] @@ -34,10 +35,10 @@ async fn make_encrypted( // this nonce should actually be unique per message in a production environment let nonce = Nonce::from_slice(b"unique nonce"); - let nonce_b64 = Some(base64::encode(nonce)); + let nonce_b64 = Some(BASE64_STANDARD.encode(nonce)); let data_enc = cipher.encrypt(nonce, data.as_bytes()).unwrap(); - let data_enc = base64::encode(data_enc); + let data_enc = BASE64_STANDARD.encode(data_enc); web::Json(Req { id, @@ -98,11 +99,11 @@ async fn encrypt_payloads( log::info!("decrypting request {id:?}"); // decode nonce from payload - let nonce = base64::decode(nonce.unwrap()).unwrap(); + let nonce = BASE64_STANDARD.decode(nonce.unwrap()).unwrap(); let nonce = Nonce::from_slice(&nonce); // decode and decrypt data field - let data_enc = base64::decode(&data).unwrap(); + let data_enc = BASE64_STANDARD.decode(&data).unwrap(); let data = cipher.decrypt(nonce, data_enc.as_slice()).unwrap(); // construct request body format with plaintext data @@ -136,11 +137,11 @@ async fn encrypt_payloads( // generate and encode nonce for later let nonce = Nonce::from_slice(b"unique nonce"); - let nonce_b64 = Some(base64::encode(nonce)); + let nonce_b64 = Some(BASE64_STANDARD.encode(nonce)); // encrypt and encode data field let data_enc = cipher.encrypt(nonce, data.as_bytes()).unwrap(); - let data_enc = base64::encode(data_enc); + let data_enc = BASE64_STANDARD.encode(data_enc); // re-pack response into JSON format let res_body = Res { diff --git a/middleware/middleware-ext-mut/src/main.rs b/middleware/middleware-ext-mut/src/main.rs index 241b8d8..7af708e 100644 --- a/middleware/middleware-ext-mut/src/main.rs +++ b/middleware/middleware-ext-mut/src/main.rs @@ -1,4 +1,4 @@ -use std::{env, io}; +use std::io; use actix_web::{ middleware, @@ -7,7 +7,7 @@ use actix_web::{ }; mod add_msg; -use crate::add_msg::{AddMsg, Msg}; +use self::add_msg::{AddMsg, Msg}; // wrap route in our middleware factory async fn index(msg: Option>) -> HttpResponse { @@ -21,8 +21,9 @@ async fn index(msg: Option>) -> HttpResponse { #[actix_web::main] async fn main() -> io::Result<()> { - env::set_var("RUST_LOG", "info"); - env_logger::init(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); + + log::info!("starting HTTP server at http://localhost:8080"); HttpServer::new(|| { App::new() diff --git a/templating/askama/Cargo.toml b/templating/askama/Cargo.toml index 8c5d355..01d50b0 100644 --- a/templating/askama/Cargo.toml +++ b/templating/askama/Cargo.toml @@ -4,9 +4,11 @@ version = "1.0.0" edition = "2021" [dependencies] -env_logger.workspace = true +actix-web-lab.workspace = true actix-web.workspace = true -askama = "0.11.0" +askama = "0.12" +env_logger.workspace = true +log.workspace = true [build-dependencies] -askama = "0.11.0" +askama = "0.12" diff --git a/templating/askama/src/main.rs b/templating/askama/src/main.rs index c62ad50..02f6ea4 100644 --- a/templating/askama/src/main.rs +++ b/templating/askama/src/main.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; -use actix_web::{middleware, web, App, HttpResponse, HttpServer, Result}; +use actix_web::{middleware, web, App, HttpServer, Responder, Result}; +use actix_web_lab::respond::Html; use askama::Template; #[derive(Template)] @@ -14,26 +15,27 @@ struct UserTemplate<'a> { #[template(path = "index.html")] struct Index; -async fn index(query: web::Query>) -> Result { - let s = if let Some(name) = query.get("name") { +async fn index(query: web::Query>) -> Result { + let html = if let Some(name) = query.get("name") { UserTemplate { name, text: "Welcome!", } .render() - .unwrap() + .expect("template should be valid") } else { - Index.render().unwrap() + Index.render().expect("template should be valid") }; - Ok(HttpResponse::Ok().content_type("text/html").body(s)) + + Ok(Html(html)) } #[actix_web::main] async fn main() -> std::io::Result<()> { - std::env::set_var("RUST_LOG", "actix_web=info"); - env_logger::init(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); + + log::info!("starting HTTP server at http://localhost:8080"); - // start http server HttpServer::new(move || { App::new() .wrap(middleware::Logger::default()) diff --git a/templating/minijinja/Cargo.toml b/templating/minijinja/Cargo.toml index be908ed..32c62d8 100644 --- a/templating/minijinja/Cargo.toml +++ b/templating/minijinja/Cargo.toml @@ -10,5 +10,5 @@ actix-utils.workspace = true env_logger.workspace = true log.workspace = true -minijinja = { version = "0.28", features = ["source"] } -minijinja-autoreload = "0.28" +minijinja = { version = "0.30", features = ["source"] } +minijinja-autoreload = "0.30" diff --git a/templating/sailfish/Cargo.toml b/templating/sailfish/Cargo.toml index b6fe15b..ea7901c 100644 --- a/templating/sailfish/Cargo.toml +++ b/templating/sailfish/Cargo.toml @@ -9,4 +9,4 @@ actix-web-lab.workspace = true env_logger.workspace = true log.workspace = true -sailfish = "0.5" +sailfish = "0.6" diff --git a/templating/tera/Cargo.toml b/templating/tera/Cargo.toml index 04167a7..488cd4e 100644 --- a/templating/tera/Cargo.toml +++ b/templating/tera/Cargo.toml @@ -8,4 +8,5 @@ actix-web.workspace = true actix-web-lab.workspace = true env_logger.workspace = true -tera = "1.8.0" +log.workspace = true +tera = "1.8" diff --git a/templating/tera/src/main.rs b/templating/tera/src/main.rs index 22c9f4e..f9648bb 100644 --- a/templating/tera/src/main.rs +++ b/templating/tera/src/main.rs @@ -33,16 +33,16 @@ async fn index( #[actix_web::main] async fn main() -> std::io::Result<()> { - std::env::set_var("RUST_LOG", "actix_web=info"); - env_logger::init(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); + + log::info!("starting HTTP server at http://localhost:8080"); - println!("Listening on: 127.0.0.1:8080, open browser and visit have a try!"); HttpServer::new(|| { let tera = Tera::new(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*")).unwrap(); App::new() .app_data(web::Data::new(tera)) - .wrap(middleware::Logger::default()) // enable logger + .wrap(middleware::Logger::default()) .service(web::resource("/").route(web::get().to(index))) .service(web::scope("").wrap(error_handlers())) }) diff --git a/templating/tinytemplate/Cargo.toml b/templating/tinytemplate/Cargo.toml index d73a781..61aaa7d 100644 --- a/templating/tinytemplate/Cargo.toml +++ b/templating/tinytemplate/Cargo.toml @@ -4,7 +4,8 @@ version = "1.0.0" edition = "2021" [dependencies] -env_logger.workspace = true -tinytemplate = "1.1" actix-web.workspace = true +env_logger.workspace = true +log.workspace = true serde_json.workspace = true +tinytemplate = "1.1" diff --git a/templating/tinytemplate/src/main.rs b/templating/tinytemplate/src/main.rs index 4d34276..06d2ba3 100644 --- a/templating/tinytemplate/src/main.rs +++ b/templating/tinytemplate/src/main.rs @@ -34,8 +34,9 @@ async fn index( #[actix_web::main] async fn main() -> std::io::Result<()> { - std::env::set_var("RUST_LOG", "actix_web=info"); - env_logger::init(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); + + log::info!("starting HTTP server at http://localhost:8080"); HttpServer::new(|| { let mut tt = TinyTemplate::new(); @@ -45,7 +46,7 @@ async fn main() -> std::io::Result<()> { App::new() .app_data(web::Data::new(tt)) - .wrap(middleware::Logger::default()) // enable logger + .wrap(middleware::Logger::default()) .service(web::resource("/").route(web::get().to(index))) .service(web::scope("").wrap(error_handlers())) }) diff --git a/templating/yarte/Cargo.toml b/templating/yarte/Cargo.toml index 69db85a..f9962c8 100644 --- a/templating/yarte/Cargo.toml +++ b/templating/yarte/Cargo.toml @@ -6,9 +6,10 @@ edition = "2021" [dependencies] actix-web.workspace = true -env_logger.workspace = true -yarte = { version = "0.15", features = ["bytes-buf", "html-min"] } derive_more.workspace = true +env_logger.workspace = true +log.workspace = true +yarte = { version = "0.15", features = ["bytes-buf", "html-min"] } [build-dependencies.yarte_helpers] version = "0.15.6" diff --git a/templating/yarte/src/main.rs b/templating/yarte/src/main.rs index 79059ce..a7149e4 100644 --- a/templating/yarte/src/main.rs +++ b/templating/yarte/src/main.rs @@ -23,10 +23,10 @@ async fn index(query: web::Query>) -> Result std::io::Result<()> { - std::env::set_var("RUST_LOG", "actix_web=info"); - env_logger::init(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); + + log::info!("starting HTTP server at http://localhost:8080"); - // start http server HttpServer::new(move || App::new().wrap(Logger::default()).service(index)) .bind(("127.0.0.1", 8080))? .run() diff --git a/unix-socket/Cargo.toml b/unix-socket/Cargo.toml index 325c6bc..b705ef8 100644 --- a/unix-socket/Cargo.toml +++ b/unix-socket/Cargo.toml @@ -4,5 +4,6 @@ version = "1.0.0" edition = "2021" [dependencies] -env_logger.workspace = true actix-web.workspace = true +env_logger.workspace = true +log.workspace = true diff --git a/unix-socket/src/main.rs b/unix-socket/src/main.rs index 9c6a923..423673f 100644 --- a/unix-socket/src/main.rs +++ b/unix-socket/src/main.rs @@ -7,8 +7,9 @@ async fn index(_req: HttpRequest) -> &'static str { #[actix_web::main] #[cfg(unix)] async fn main() -> std::io::Result<()> { - ::std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info"); - env_logger::init(); + env_logger::init_from_env(env_logger::Env::new().default_filter_or("info")); + + log::info!("starting HTTP server at http://localhost:8080"); HttpServer::new(|| { App::new() @@ -24,6 +25,6 @@ async fn main() -> std::io::Result<()> { #[cfg(not(unix))] fn main() -> std::io::Result<()> { - println!("not supported"); + log::info!("Example only runs on UNIX"); Ok(()) }