Skip to content

Commit

Permalink
Fix lint issues (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
zarvd authored Apr 12, 2024
1 parent 17ec554 commit 6ec2ab6
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 29 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,43 @@ on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
unit-test:
name: Unit test using ${{matrix.rust}}
name: Unit test
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
rust: [ 1.77, nightly, beta, stable ]
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
toolchain: stable
components: clippy
- uses: extractions/setup-just@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install cargo-nextest
uses: taiki-e/install-action@nextest
- name: Run unit tests
run: |
cargo test --release
just unit-test
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: clippy
- uses: extractions/setup-just@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run lint
run: cargo clippy --all-targets --all-features
run: just lint
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18" }
tower-http = { version = "0.5.2", features = ["add-extension", "trace", "cors", "timeout"] }
tokio = { version = "1.37.0", features = ["rt-multi-thread", "signal", "macros", "net", "io-util"] }
axum = { version = "0.7" }
axum = { version = "0.7.5" }
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[<img alt="github" height="20" src="https://img.shields.io/badge/github-zarvd/echoserver-8da0cb?style=for-the-badge&labelColor=555555&logo=github">](https://github.com/zarvd/echoserver)
[<img alt="crates.io" height="20" src="https://img.shields.io/crates/v/echoserver.svg?style=for-the-badge&color=fc8d62&logo=rust">](https://crates.io/crates/echoserver)
[<img alt="docs.rs" height="20" src="https://img.shields.io/docsrs/echoserver?style=for-the-badge">](https://docs.rs/echoserver)
[<img alt="build status" height="20" src="https://img.shields.io/github/actions/workflow/status/zarvd/echoserver/ci.yml?branch=master&style=for-the-badge">](https://github.com/zarvd/echoserver/actions?query%3Amaster)
[<img alt="dependency status" height="20" src="https://deps.rs/repo/github/zarvd/echoserver/status.svg?style=for-the-badge&t=0">](https://deps.rs/repo/github/zarvd/echoserver)

Expand Down
21 changes: 12 additions & 9 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
image_repo := "ghcr.io/zarvd/echoserver"

default:
just --list

# Build the project
build:
cargo build --release

run:
cargo run --release
cargo build

# Format code with rust
fmt:
cargo fmt

test:
cargo test --release
# Run unit tests against the current platform
unit-test:
cargo nextest run

# Lint code with clippy
lint:
cargo clippy --release
cargo fmt --all -- --check
cargo clippy --all-targets --all-features

# Clean workspace
clean:
cargo clean

image_repo := "ghcr.io/zarvd/echoserver"
# Build docker image
image tag: clean
docker buildx build ./ \
--output=type=docker \
Expand Down
4 changes: 2 additions & 2 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ pub async fn serve(addr: SocketAddr) -> Result<()> {

let listener = TcpListener::bind(addr)
.await
.expect(&format!("bind HTTP server on {addr}"));
.unwrap_or_else(|e| panic!("failed to bind HTTP server on {addr}: {e}"));
axum::serve(listener, app)
.await
.expect(&format!("serve HTTP server on {addr}"));
.unwrap_or_else(|e| panic!("failed to serve HTTP server on {addr}: {e}"));

Ok(())
}
2 changes: 1 addition & 1 deletion src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub async fn shutdown() {
() = recv_signal_and_shutdown(SignalKind::terminate()) => {}
};

info!("recv signal and shutting down");
info!("received signal and shutting down");
}

async fn recv_signal_and_shutdown(kind: SignalKind) {
Expand Down
4 changes: 2 additions & 2 deletions src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ pub async fn serve(addr: SocketAddr) -> Result<()> {

let lis = TcpListener::bind(addr)
.await
.expect(&format!("bind TCP server on {addr}"));
.unwrap_or_else(|e| panic!("failed to bind TCP server on {addr}: {e}"));

loop {
match lis.accept().await {
Ok((socket, _remote_addr)) => {
tokio::spawn(handle(socket));
}
Err(e) => {
error!("[TCP/{}] Failed to accept new socket: {}", addr, e);
error!("[TCP/{addr}] Failed to accept new socket: {e}");
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn serve(addr: SocketAddr) -> Result<()> {
let socket = Arc::new(
UdpSocket::bind(addr)
.await
.expect(&format!("bind TCP server on {addr}")),
.unwrap_or_else(|e| panic!("failed to bind UDP server on {addr}: {e}")),
);

loop {
Expand All @@ -30,10 +30,10 @@ pub async fn serve(addr: SocketAddr) -> Result<()> {
Ok((n, remote_addr)) => {
handle(socket.clone(), remote_addr, &buf[0..n])
.await
.expect(&format!("echo data from UDP server {addr}"));
.unwrap_or_else(|e| panic!("failed to echo data from UDP server {addr}: {e}"));
}
Err(e) => {
error!("Failed to receive data: {}", e);
error!("[UDP/{addr}] Failed to receive data: {e}");
}
}
}
Expand Down

0 comments on commit 6ec2ab6

Please sign in to comment.