From 137ceedadd1a61e13be2d5ab30e6bcbc99a17d11 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Tue, 20 Aug 2024 21:06:10 +0300 Subject: [PATCH] feat: add `cargo generate` support --- .env | 1 - .env.example | 1 + .gitignore | 1 + Cargo.toml | 4 ++-- Dockerfile | 2 +- config/base.toml | 2 +- src/main.rs | 4 ++-- tests/health_check.rs | 2 +- 8 files changed, 9 insertions(+), 8 deletions(-) delete mode 100644 .env create mode 100644 .env.example diff --git a/.env b/.env deleted file mode 100644 index 668d026..0000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -DATABASE_URL=postgres://postgres:password@localhost:5432/axum-template diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..4e98827 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +DATABASE_URL=postgres://postgres:password@localhost:5432/{{project-name}} diff --git a/.gitignore b/.gitignore index ea8c4bf..fedaa2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.env diff --git a/Cargo.toml b/Cargo.toml index ad57710..43f7b64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "axum-template" +name = "{{project-name}}" version = "0.1.0" edition = "2021" authors = ["Kristofers Solo "] @@ -9,7 +9,7 @@ path = "src/lib.rs" [[bin]] path = "src/main.rs" -name = "axum-template" +name = "{{project-name}}" [dependencies] axum = "0.7" diff --git a/Dockerfile b/Dockerfile index 060291d..4aedaea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,7 +25,7 @@ RUN apt-get update -y \ && apt-get clean -y \ && rm -rf /var/lib/apt/lists/* -COPY --from=builder /app/target/release/axum-template axum-template +COPY --from=builder /app/target/release/{{project-name}} {{project-name}} COPY config config ENV APP_ENVIRONMENT production ENTRYPOINT ["./axum-template"] diff --git a/config/base.toml b/config/base.toml index 229d5f4..ab725b8 100644 --- a/config/base.toml +++ b/config/base.toml @@ -6,4 +6,4 @@ host = "127.0.0.1" port = 5432 username = "postgres" password = "password" -database_name = "axum-template" +database_name = "{{project-name}}" diff --git a/src/main.rs b/src/main.rs index 8389562..88d4b06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use axum_template::{ +use {{crate_name}}::{ config::get_config, routes::route, telemetry::{get_subscriber, init_subscriber}, @@ -8,7 +8,7 @@ use tokio::net::TcpListener; #[tokio::main] async fn main() -> Result<(), std::io::Error> { - let subscriber = get_subscriber("axum-template", "info", std::io::stdout); + let subscriber = get_subscriber("{{project-name}}", "info", std::io::stdout); init_subscriber(subscriber); let config = get_config().expect("Failed to read configuation."); let pool = PgPoolOptions::new().connect_lazy_with(config.database.with_db()); diff --git a/tests/health_check.rs b/tests/health_check.rs index b60d895..c21799d 100644 --- a/tests/health_check.rs +++ b/tests/health_check.rs @@ -1,4 +1,4 @@ -use axum_template::{ +use {{crate_name}}::{ config::{get_config, DatabaseSettings}, routes::route, telemetry::{get_subscriber, init_subscriber},