Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump loco to 0.14.0 #202

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions loco/hello-world/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[alias]
loco = "run --bin hello_world-cli --"
loco-tool = "run --"

playground = "run --example playground"
Empty file.
8 changes: 0 additions & 8 deletions loco/hello-world/.devcontainer/Dockerfile

This file was deleted.

9 changes: 0 additions & 9 deletions loco/hello-world/.devcontainer/devcontainer.json

This file was deleted.

12 changes: 0 additions & 12 deletions loco/hello-world/.devcontainer/docker-compose.yml

This file was deleted.

40 changes: 31 additions & 9 deletions loco/hello-world/.github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ jobs:
steps:
- name: Checkout the code
uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@stable
with:
profile: ${{ env.TOOLCHAIN_PROFILE }}
toolchain: ${{ env.RUST_TOOLCHAIN }}
override: true
components: rustfmt
- name: Run cargo fmt
uses: actions-rs/cargo@v1
Expand All @@ -43,11 +41,9 @@ jobs:
steps:
- name: Checkout the code
uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@stable
with:
profile: ${{ env.TOOLCHAIN_PROFILE }}
toolchain: ${{ env.RUST_TOOLCHAIN }}
override: true
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: Run cargo clippy
Expand All @@ -62,19 +58,45 @@ jobs:

permissions:
contents: read

services:
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- "6379:6379"
postgres:
image: postgres
env:
POSTGRES_DB: postgres_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
# Set health checks to wait until postgres has started
options: --health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout the code
uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@stable
with:
profile: ${{ env.TOOLCHAIN_PROFILE }}
toolchain: ${{ env.RUST_TOOLCHAIN }}
override: true
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --all
env:
REDIS_URL: redis://localhost:${{job.services.redis.ports[6379]}}
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres_test

11 changes: 7 additions & 4 deletions loco/hello-world/.gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
**/config/local.yaml
**/config/*.local.yaml
**/config/production.yaml

# Generated by Cargo
# will have compiled files and executables
debug/
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
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

*.sqlite
/target
.shuttle*
Secrets*.toml
2 changes: 2 additions & 0 deletions loco/hello-world/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
max_width = 100
use_small_heuristics = "Default"
37 changes: 21 additions & 16 deletions loco/hello-world/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@
name = "hello_world"
version = "0.1.0"
edition = "2021"
publish = false
default-run = "hello_world-cli"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
[workspace.dependencies]
loco-rs = { version = "0.14.0", default-features = false }

async-trait = "0.1.74"
axum = "0.7.1"
loco-rs = { version = "0.9.0", default-features = false, features = ["cli"] }
shuttle-axum = { version = "0.51.0", default-features = false, features = ["axum-0-7"] }
[dependencies]
shuttle-axum = "0.51.0"
shuttle-runtime = { version = "0.51.0", default-features = false }
serde = "*"
serde_json = "*"
tokio = "1.33.0"
tracing = "0.1.40"

loco-rs = { workspace = true , features = ["cli"] }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1" }
tokio = { version = "1.33.0", default-features = false, features = [
"rt-multi-thread",
] }
async-trait = { version = "0.1.74" }
axum = { version = "0.8.1" }
tracing = { version = "0.1.40" }
tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json"] }
regex = { version = "1.11.1" }

[[bin]]
name = "hello_world-cli"
Expand All @@ -30,10 +38,7 @@ name = "hello_world"
path = "src/bin/shuttle.rs"

[dev-dependencies]
serial_test = "*"
rstest = "*"
loco-rs = { version = "0.9.0", default-features = false, features = [
"testing",
"cli",
] }
insta = { version = "*", features = ["redactions", "yaml", "filters"] }
loco-rs = { workspace = true, features = ["testing"] }
serial_test = { version = "3.1.1" }
rstest = { version = "0.21.0" }
insta = { version = "1.34.0", features = ["redactions", "yaml", "filters"] }
25 changes: 12 additions & 13 deletions loco/hello-world/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
# Shuttle Loco template :train:
# Welcome to Loco :train:

Welcome to the [Loco](https://loco.rs) Hello World Shuttle Template, designed with a focus on controllers and views (response schema). This minimalistic template comes with several features to kickstart your project:
[Loco](https://loco.rs) is a web and API framework running on Rust.

## REST API Service without a Database

* **Controllers:** Handle web requests parameters, body, validation, and render a response that is content-aware. We use Axum for the best performance, simplicity, and extensibility. Controllers also allow you to easily build middlewares, which can be used to add logic such as authentication, logging, or error handling before passing requests to the main controller actions.
* **Views:** Loco can integrate with templating engines to generate dynamic HTML content from templates.
* **Background Jobs:** Perform compute or I/O intensive jobs in the background with a Redis backed queue, or with threads. Implementing a worker is as simple as implementing a perform function for the Worker trait.
* **Scheduler:** Simplifies the traditional, often cumbersome crontab system, making it easier and more elegant to schedule tasks or shell scripts.
* **Mailers:** A mailer will deliver emails in the background using the existing loco background worker infrastructure. It will all be seamless for you.
* **Storage:** In Loco Storage, we facilitate working with files through multiple operations. Storage can be in-memory, on disk, or use cloud services such as AWS S3, GCP, and Azure.
* **Cache:** Loco provides an cache layer to improve application performance by storing frequently accessed data.

So see more Loco features, check out our [documentation website](https://loco.rs/docs/getting-started/tour/).
This is the **SaaS starter** which includes a `User` model and authentication based on JWT.
It also include configuration sections that help you pick either a frontend or a server-side template set up for your fullstack server.

## Quick Start

Expand All @@ -21,3 +12,11 @@ To launch your app, simply use the following command:
```sh
shuttle run
```

## Full Stack Serving

You can check your [configuration](config/development.yaml) to pick either frontend setup or server-side rendered template, and activate the relevant configuration sections.

## Getting help

Check out [a quick tour](https://loco.rs/docs/getting-started/tour/) or [the complete guide](https://loco.rs/docs/getting-started/guide/).
9 changes: 9 additions & 0 deletions loco/hello-world/Shuttle.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[deploy]
include = [
"config/production.yaml"
]

[build]
assets = [
"config/production.yaml"
]
38 changes: 13 additions & 25 deletions loco/hello-world/config/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
logger:
# Enable or disable logging.
enable: true
# Enable pretty backtrace (sets RUST_BACKTRACE=1)
pretty_backtrace: true
# Log level, options: trace, debug, info, warn or error.
level: debug
# Define the logging format. options: compact, pretty or Json
# Define the logging format. options: compact, pretty or json
format: compact
# By default the logger has filtering only logs that came from your code or logs that came from `loco` framework. to see all third party libraries
# Uncomment the line below to override to see all third party libraries you can enable this config and override the logger filters.
Expand All @@ -15,31 +17,17 @@ logger:
# Web server configuration
server:
# Port on which the server will listen. the server binding is 0.0.0.0:{PORT}
port: 8000
port: 5150
# Binding for the server (which interface to bind to)
binding: localhost
# The UI hostname or IP address that mailers will point to.
host: http://localhost
# Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block
middlewares:
# Enable Etag cache header middleware
etag:
enable: true
# Allows to limit the payload size request. payload that bigger than this file will blocked the request.
limit_payload:
# Enable/Disable the middleware.
enable: true
# the limit size. can be b,kb,kib,mb,mib,gb,gib
body_limit: 5mb
# Generating a unique request ID and enhancing logging with additional information such as the start and completion of request processing, latency, status code, and other request details.
logger:
# Enable/Disable the middleware.
enable: true
# when your code is panicked, the request still returns 500 status code.
catch_panic:
# Enable/Disable the middleware.
enable: true
# Timeout for incoming requests middleware. requests that take more time from the configuration will cute and 408 status code will returned.
timeout_request:
# Enable/Disable the middleware.
enable: false
# Duration time in milliseconds.
timeout: 5000

# Initializers Configuration
# initializers:
# oauth2:
# authorization_code: # Authorization code grant type
# - client_identifier: google # Identifier for the OAuth2 provider. Replace 'google' with your provider's name if different, must be unique within the oauth2 config.
# ... other fields
38 changes: 13 additions & 25 deletions loco/hello-world/config/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
logger:
# Enable or disable logging.
enable: true
# Enable pretty backtrace (sets RUST_BACKTRACE=1)
pretty_backtrace: true
# Log level, options: trace, debug, info, warn or error.
level: debug
# Define the logging format. options: compact, pretty or Json
# Define the logging format. options: compact, pretty or json
format: compact
# By default the logger has filtering only logs that came from your code or logs that came from `loco` framework. to see all third party libraries
# Uncomment the line below to override to see all third party libraries you can enable this config and override the logger filters.
Expand All @@ -15,31 +17,17 @@ logger:
# Web server configuration
server:
# Port on which the server will listen. the server binding is 0.0.0.0:{PORT}
port: 8000
port: 5150
# Binding for the server (which interface to bind to)
binding: localhost
# The UI hostname or IP address that mailers will point to.
host: http://localhost
# Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block
middlewares:
# Enable Etag cache header middleware
etag:
enable: true
# Allows to limit the payload size request. payload that bigger than this file will blocked the request.
limit_payload:
# Enable/Disable the middleware.
enable: true
# the limit size. can be b,kb,kib,mb,mib,gb,gib
body_limit: 5mb
# Generating a unique request ID and enhancing logging with additional information such as the start and completion of request processing, latency, status code, and other request details.
logger:
# Enable/Disable the middleware.
enable: true
# when your code is panicked, the request still returns 500 status code.
catch_panic:
# Enable/Disable the middleware.
enable: true
# Timeout for incoming requests middleware. requests that take more time from the configuration will cute and 408 status code will returned.
timeout_request:
# Enable/Disable the middleware.
enable: false
# Duration time in milliseconds.
timeout: 5000

# Initializers Configuration
# initializers:
# oauth2:
# authorization_code: # Authorization code grant type
# - client_identifier: google # Identifier for the OAuth2 provider. Replace 'google' with your provider's name if different, must be unique within the oauth2 config.
# ... other fields
Loading
Loading