https://github.com/mloning/zero2prod-rs
Code for Zero to Production in Rust
https://github.com/mloning/zero2prod-rs
rust zero2prod
Last synced: 2 months ago
JSON representation
Code for Zero to Production in Rust
- Host: GitHub
- URL: https://github.com/mloning/zero2prod-rs
- Owner: mloning
- Created: 2025-02-01T10:05:01.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-03-16T14:14:14.000Z (3 months ago)
- Last Synced: 2025-03-19T03:41:39.580Z (3 months ago)
- Topics: rust, zero2prod
- Language: Rust
- Homepage:
- Size: 272 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Code for Zero to Production in Rust
My code from working through [Zero to Production in Rust].
[Zero to Production in Rust]: https://www.zero2prod.com
## Initial setup
- Install Rust
- Install Docker
- `brew install libpq` to install `psql`
- `cargo install sqlx-cli --no-default-features --features rustls,postgres`
- `cargo install bunyan` for pretty printing logs## Development
### Run app
- `bash scripts/init_db.sh` to start database server in Docker container (detached) for testing
- `SKIP_DOCKER=true bash scripts/init_db.sh` to apply migrations to database running in container
- `psql -h localhost -p 5432 -U postgres` to connect to database server from command line
- `cargo run | bunyan` to run app with pretty-printed logs
- `cargo watch --exec 'run | bunyan' --ignore *.md` to run app on file changes### Run tests
- `cargo watch --exec check --exec test --ignore *.md` to run tests on file changes
- `TEST_LOG=true cargo test` to see logs from tests, or `TEST_LOG=true cargo test | bunyan` with pretty printingTo manually test API endpoints, use for example:
- `curl -v http://127.0.0.1:8000/health_check`
- `curl -v http://127.0.0.1:8000/subscriptions -H "Content-Type: application/x-www-form-urlencoded" -d "[email protected]&name=tester"`#### Known issues
If you see the following error, you can increase the maximum number of open file handles:
> thread 'actix-server worker ...' panicked at ... called `Result::unwrap()` on an `Err` value: Os { code: 24, kind: Uncategorized, message: "Too many open files" }
- `ulimit -Sn` to see the current soft limit
- `ulimit -Sn ` to set a new limit for the current Shell session, e.g. `ulimit -Sn 1000`### Inspect database
- `psql -h localhost -p 5432 -U postgres` to connect to the database server from command line
### Build Docker image
- `cargo sqlx prepare --workspace`, to work with sqlx offline, together with `SQLX_OFFLINE=true`
- `docker build --tag zero2prod --file Dockerfile .`
- `docker run -p 8000:8000 zero2prod`## Notes
### Tools
- `cargo clippy` for linting
- `cargo tarpaulin --ignore-tests` for code coverage
- `cargo watch` for triggering commands automatically on code changes
- `cargo audit` to check for vulnerabilities
- `cargo expand` to show result of macro expansions
- `cargo +nightly udeps` to remove unused dependencies, requires `rustup toolchain install nightly`
- `cargo tree` to display dependency tree, useful for debugging incompatible dependencies### Commands
- `rustup update` to update the Rust toolchain including `rustc` and `cargo`
- `tmux new-session -t ` to attach to the same session multiple times and switch windows independently, using tmux grouped sessions (see [SO post](https://unix.stackexchange.com/a/24288)), e.g. for monitoring output from `cargo watch` commands in separate windows