-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
378 additions
and
129 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
# Running | ||
|
||
# Sqlx | ||
First, export the database url: | ||
|
||
export DATABASE_URL=postgres://postgres:password@localhost:5432/newsletter | ||
sqlx migrate add create_subscriptions_table | ||
|
||
Then, start the database using docker: | ||
|
||
./scripts/init_db.sh | ||
|
||
Finally, run the project: | ||
|
||
cargo run | ||
|
||
To enable nice display of logs: | ||
|
||
RUST_LOG=trace cargo run | bunyan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#![allow(clippy::toplevel_ref_arg)] | ||
pub mod configuration; | ||
pub mod routes; | ||
pub mod startup; | ||
pub mod telemetry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use tracing::subscriber::set_global_default; | ||
use tracing::Subscriber; | ||
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer}; | ||
use tracing_log::LogTracer; | ||
use tracing_subscriber::fmt::MakeWriter; | ||
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry}; | ||
|
||
/// Compose multiple layers into a `tracing`'s subscriber. | ||
/// | ||
/// # Implementation Notes | ||
/// | ||
/// We are using `impl Subscriber` as return type to avoid having to | ||
/// spell out the actual type of the returned subscriber, which is | ||
/// indeed quite complex. | ||
/// We need to explicitly call out that the returned subscriber is | ||
/// `Send` and `Sync` to make it possible to pass it to `init_subscriber` | ||
/// later on. | ||
pub fn get_subscriber<Sink>( | ||
name: String, | ||
env_filter: String, | ||
sink: Sink, | ||
) -> impl Subscriber + Sync + Send | ||
where | ||
// This "weird" syntax is a higher-ranked trait bound (HRTB) | ||
// It basically means that Sink implements the `MakeWriter` | ||
// trait for all choices of the lifetime parameter `'a` | ||
// Check out https://doc.rust-lang.org/nomicon/hrtb.html | ||
// for more details. | ||
Sink: for<'a> MakeWriter<'a> + Send + Sync + 'static, | ||
{ | ||
let env_filter = | ||
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(env_filter)); | ||
let formatting_layer = BunyanFormattingLayer::new(name, sink); | ||
Registry::default() | ||
.with(env_filter) | ||
.with(JsonStorageLayer) | ||
.with(formatting_layer) | ||
} | ||
/// Register a subscriber as global default to process span data. | ||
/// | ||
/// It should only be called once! | ||
pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) { | ||
LogTracer::init().expect("Failed to set logger"); | ||
set_global_default(subscriber).expect("Failed to set subscriber"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters