mirror of https://github.com/zino-rs/zino
Update examples
This commit is contained in:
parent
4ff0d25eb3
commit
a4c115ad2a
|
@ -1,6 +1,7 @@
|
|||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
/examples/**/target
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"zino",
|
||||
"zino-core",
|
||||
"zino-derive",
|
||||
"zino-model",
|
||||
"zino",
|
||||
"examples/axum-app/app",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"axum-app",
|
||||
]
|
||||
|
||||
[profile.release]
|
||||
lto = "fat"
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
|
@ -0,0 +1,4 @@
|
|||
# Examples
|
||||
|
||||
This folder contains numerous example showing how to use zino.
|
||||
Each example is setup as its own crate so its dependencies are clear.
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "axum-app"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
rust-version = "1.68"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
@ -11,10 +11,10 @@ serde_json = { version = "1.0.91" }
|
|||
tracing = { version = "0.1.37" }
|
||||
|
||||
[dependencies.zino]
|
||||
path = "../../../zino"
|
||||
version = "0.4.0"
|
||||
path = "../../zino"
|
||||
version = "0.4.1"
|
||||
features = ["axum"]
|
||||
|
||||
[dependencies.zino-model]
|
||||
path = "../../../zino-model"
|
||||
version = "0.3.2"
|
||||
path = "../../zino-model"
|
||||
version = "0.3.3"
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
name = "data-cube"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
|
||||
[main]
|
||||
host = "127.0.0.1"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
name = "data-cube"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
|
||||
[main]
|
||||
host = "127.0.0.1"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "zino-core"
|
||||
description = "Core types and traits for zino."
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
rust-version = "1.68"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
|
|
@ -9,7 +9,7 @@ use metrics_exporter_prometheus::{Matcher, PrometheusBuilder};
|
|||
use metrics_exporter_tcp::TcpBuilder;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env, io,
|
||||
env, fs, io,
|
||||
net::IpAddr,
|
||||
path::{Path, PathBuf},
|
||||
sync::{LazyLock, OnceLock},
|
||||
|
@ -154,11 +154,13 @@ pub trait Application {
|
|||
} else {
|
||||
let project_dir = Self::project_dir();
|
||||
let log_dir = project_dir.join("./log");
|
||||
if log_dir.exists() {
|
||||
log_dir
|
||||
} else {
|
||||
project_dir.join("../log")
|
||||
if !log_dir.exists() {
|
||||
fs::create_dir(log_dir.as_path()).unwrap_or_else(|err| {
|
||||
let log_dir = log_dir.to_string_lossy();
|
||||
panic!("failed to create the log directory `{log_dir}`: {err}");
|
||||
});
|
||||
}
|
||||
log_dir
|
||||
};
|
||||
let file_appender = rolling::hourly(rolling_file_dir, format!("{app_name}.{app_env}"));
|
||||
let (non_blocking_appender, worker_guard) = tracing_appender::non_blocking(file_appender);
|
||||
|
|
|
@ -11,11 +11,12 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
mod crypto;
|
||||
|
||||
pub mod application;
|
||||
pub mod authentication;
|
||||
pub mod cache;
|
||||
pub mod channel;
|
||||
pub mod crypto;
|
||||
pub mod database;
|
||||
pub mod datetime;
|
||||
pub mod request;
|
||||
|
|
|
@ -35,11 +35,7 @@ impl State {
|
|||
let env = &self.env;
|
||||
let project_dir = env::current_dir()
|
||||
.expect("the project directory does not exist or permissions are insufficient");
|
||||
let config_file = if project_dir.join("./config").exists() {
|
||||
project_dir.join(format!("./config/config.{env}.toml"))
|
||||
} else {
|
||||
project_dir.join(format!("../config/config.{env}.toml"))
|
||||
};
|
||||
let config_file = project_dir.join(format!("./config/config.{env}.toml"));
|
||||
let config: Value = fs::read_to_string(&config_file)
|
||||
.unwrap_or_else(|err| {
|
||||
let config_file = config_file.to_string_lossy();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "zino-derive"
|
||||
description = "Derived traits for zino."
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
rust-version = "1.68"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
@ -20,4 +20,4 @@ syn = { version = "1.0.107", features = ["full", "extra-traits"] }
|
|||
|
||||
[dependencies.zino-core]
|
||||
path = "../zino-core"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "zino-model"
|
||||
description = "Model types for zino."
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
||||
rust-version = "1.68"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
@ -15,8 +15,8 @@ serde = { version = "1.0.152", features = ["derive"] }
|
|||
|
||||
[dependencies.zino-core]
|
||||
path = "../zino-core"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
|
||||
[dependencies.zino-derive]
|
||||
path = "../zino-derive"
|
||||
version = "0.3.2"
|
||||
version = "0.3.3"
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "zino"
|
||||
description = "Full featured web application framework for Rust."
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
||||
rust-version = "1.68"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
|
@ -12,6 +12,9 @@ repository = "https://github.com/photino/zino"
|
|||
documentation = "https://docs.rs/zino"
|
||||
readme = "README.md"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["axum"]
|
||||
|
||||
[features]
|
||||
axum = ["dep:axum", "dep:tokio", "dep:tokio-stream", "dep:tower", "dep:tower-http"]
|
||||
|
||||
|
@ -37,4 +40,4 @@ tower-http = { version = "0.3.5", features = ["full"], optional = true }
|
|||
|
||||
[dependencies.zino-core]
|
||||
path = "../zino-core"
|
||||
version = "0.4.0"
|
||||
version = "0.4.1"
|
|
@ -87,12 +87,7 @@ impl Application for AxumCluster {
|
|||
|
||||
let project_dir = Self::project_dir();
|
||||
let public_dir = project_dir.join("./public");
|
||||
let static_site_dir = if public_dir.exists() {
|
||||
public_dir
|
||||
} else {
|
||||
project_dir.join("../public")
|
||||
};
|
||||
let index_file = static_site_dir.join("./index.html");
|
||||
let index_file = public_dir.join("./index.html");
|
||||
let internal_server_error_handler = |err: io::Error| async move {
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
|
@ -101,7 +96,7 @@ impl Application for AxumCluster {
|
|||
};
|
||||
let serve_file_service = routing::get_service(ServeFile::new(index_file))
|
||||
.handle_error(internal_server_error_handler);
|
||||
let serve_dir_service = routing::get_service(ServeDir::new(static_site_dir))
|
||||
let serve_dir_service = routing::get_service(ServeDir::new(public_dir))
|
||||
.handle_error(internal_server_error_handler);
|
||||
|
||||
runtime.block_on(async {
|
||||
|
|
|
@ -56,14 +56,10 @@ pub type Result<T = axum::http::Response<axum::body::Full<axum::body::Bytes>>> =
|
|||
#[doc(no_inline)]
|
||||
pub use zino_core::{
|
||||
application::Application,
|
||||
authentication::{AccessKeyId, Authentication, SecretAccessKey, SecurityToken},
|
||||
cache::GlobalCache,
|
||||
channel::{CloudEvent, Subscription},
|
||||
database::{Column, ConnectionPool, Model, Mutation, Query, Schema},
|
||||
database::{Model, Query, Schema},
|
||||
datetime::DateTime,
|
||||
request::{Context, RequestContext, Validation},
|
||||
response::{Rejection, Response, ResponseCode},
|
||||
schedule::{AsyncCronJob, CronJob, Job, JobScheduler},
|
||||
state::State,
|
||||
BoxError, BoxFuture, Map, Uuid,
|
||||
request::RequestContext,
|
||||
response::{Rejection, Response},
|
||||
schedule::{AsyncCronJob, CronJob},
|
||||
BoxFuture, Map, Uuid,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue