3 个版本
| 0.1.2 | 2023 年 2 月 20 日 |
|---|---|
| 0.1.1 | 2023 年 2 月 19 日 |
| 0.1.0 | 2023 年 2 月 19 日 |
#1107 在 HTTP 服务器
21KB
192 行
Rust Greeter
一个使用 axum 构建 API 的 rust-lang 示例。
示例应用程序将被交叉编译为:
- linux/arm64 (
aarch64-unknown-linux-musl) - linux/amd64 (
x86_64-unknown-linux-musl)
示例使用 cargo-zigbuild 作为交叉编译的工具。
先决条件
本地构建
cargo build
启动服务器:
./target/debug/rgreeter
测试
在新的终端中启动应用程序以运行集成测试:
PORT=8080 cargo run
在另一个终端中运行:
cargo test
测试应用程序
一旦服务器启动,您可以尝试以下 REST URI:
- 默认的
curl https://:3000/返回Hello World! - 问候:
curl https://:3000/greet返回Hello! 匿名! - 问候一个人:
curl https://:3000/greet?name=Jack返回Hello! Jack!
构建并推送镜像到 Docker 仓库
在 $PROJECT_HOME 下创建一个名为 .env 的文件,
注意:您可以将文件 .env.example 复制到
.env并更新您的设置
PLUGIN_USERNAME=<container registry username>
PLUGIN_PASSWORD=<container registry password>
PLUGIN_REPO=<container image repo to push image>
PLUGIN_REGISTRY=<container registry to use>
例如。
PLUGIN_USERNAME=octocat
PLUGIN_PASSWORD=octocat registry password
PLUGIN_REPO=ghcr.io/octocat/rgreeter
PLUGIN_REGISTRY=ghcr.io
task ci
一旦镜像被推送,运行以下命令:
docker-compose up
使用命令 docker ps 查找公开的端口,并使用 URI 测试应用程序。
注意:如果您的机器上端口
8080不可用,请尝试使用其他端口。
依赖项
~10–18MB
~240K SLoC