Compare commits
7 Commits
v0.1.0-dev
...
v0.1.0-dev
Author | SHA1 | Date | |
---|---|---|---|
f105de7c80 | |||
9b77a8dd78 | |||
dda88ce0a0 | |||
5893710431 | |||
0a678228dd | |||
bfc14c96a7 | |||
f2005de668 |
@@ -19,7 +19,15 @@ jobs:
|
|||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.85.0
|
toolchain: 1.85.0
|
||||||
- run: cargo check
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||||
|
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||||
|
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||||
|
cargo check
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: Test Suite
|
name: Test Suite
|
||||||
@@ -29,7 +37,15 @@ jobs:
|
|||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.85.0
|
toolchain: 1.85.0
|
||||||
- run: cargo test
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||||
|
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||||
|
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||||
|
cargo test
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
name: Rustfmt
|
name: Rustfmt
|
||||||
@@ -40,7 +56,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
toolchain: 1.85.0
|
toolchain: 1.85.0
|
||||||
- run: rustup component add rustfmt
|
- run: rustup component add rustfmt
|
||||||
- run: cargo fmt --all -- --check
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||||
|
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||||
|
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
name: Clippy
|
name: Clippy
|
||||||
@@ -51,7 +75,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
toolchain: 1.85.0
|
toolchain: 1.85.0
|
||||||
- run: rustup component add clippy
|
- run: rustup component add clippy
|
||||||
- run: cargo clippy -- -D warnings
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||||
|
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||||
|
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||||
|
cargo clippy -- -D warnings
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: build
|
name: build
|
||||||
@@ -61,5 +93,13 @@ jobs:
|
|||||||
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.85.0
|
toolchain: 1.85.0
|
||||||
- run: cargo build
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key
|
||||||
|
chmod 600 ~/.ssh/gitlab_deploy_key
|
||||||
|
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/gitlab_deploy_key
|
||||||
|
cargo build --release
|
||||||
|
|
||||||
|
@@ -9,3 +9,4 @@ serde = { version = "1.0.218", features = ["derive"] }
|
|||||||
serde_json = { version = "1.0.139" }
|
serde_json = { version = "1.0.139" }
|
||||||
tokio = { version = "1.44.1", features = ["rt-multi-thread"] }
|
tokio = { version = "1.44.1", features = ["rt-multi-thread"] }
|
||||||
tracing-subscriber = "0.3.19"
|
tracing-subscriber = "0.3.19"
|
||||||
|
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.2.0" }
|
||||||
|
4
src/callers/common.rs
Normal file
4
src/callers/common.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// basic handler that responds with a static string
|
||||||
|
pub async fn root() -> &'static str {
|
||||||
|
"Hello, World!"
|
||||||
|
}
|
7
src/callers/mod.rs
Normal file
7
src/callers/mod.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
pub mod common;
|
||||||
|
pub mod register;
|
||||||
|
|
||||||
|
pub mod endpoints {
|
||||||
|
pub const ROOT: &str = "/";
|
||||||
|
pub const REGISTER: &str = "api/v2/register";
|
||||||
|
}
|
12
src/callers/register.rs
Normal file
12
src/callers/register.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use axum::{Json, http::StatusCode};
|
||||||
|
|
||||||
|
use crate::models;
|
||||||
|
|
||||||
|
pub async fn register_user(
|
||||||
|
Json(payload): Json<models::common::CreateUser>,
|
||||||
|
) -> (StatusCode, Json<models::common::User>) {
|
||||||
|
let user = models::common::User {
|
||||||
|
username: payload.username.clone(),
|
||||||
|
};
|
||||||
|
(StatusCode::CREATED, Json(user))
|
||||||
|
}
|
10
src/config/mod.rs
Normal file
10
src/config/mod.rs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
pub fn get_full() -> String {
|
||||||
|
get_address() + ":" + &get_port()
|
||||||
|
}
|
||||||
|
fn get_address() -> String {
|
||||||
|
String::from("0.0.0.0")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_port() -> String {
|
||||||
|
String::from("3000")
|
||||||
|
}
|
36
src/main.rs
36
src/main.rs
@@ -1,9 +1,11 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
Json, Router,
|
Router,
|
||||||
http::StatusCode,
|
|
||||||
routing::{get, post},
|
routing::{get, post},
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
pub mod callers;
|
||||||
|
pub mod config;
|
||||||
|
pub mod models;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
@@ -12,28 +14,14 @@ async fn main() {
|
|||||||
|
|
||||||
// build our application with a route
|
// build our application with a route
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
// `GET /` goes to `root`
|
.route(callers::endpoints::ROOT, get(callers::common::root))
|
||||||
.route("/", get(root));
|
.route(
|
||||||
// `POST /users` goes to `create_user`
|
callers::endpoints::REGISTER,
|
||||||
// .route("/users", post(create_user));
|
post(callers::register::register_user),
|
||||||
|
);
|
||||||
|
|
||||||
// run our app with hyper, listening globally on port 3000
|
// run our app with hyper, listening globally on port 3000
|
||||||
let listener = tokio::net::TcpListener::bind(get_full()).await.unwrap();
|
let url = config::get_full();
|
||||||
|
let listener = tokio::net::TcpListener::bind(url).await.unwrap();
|
||||||
axum::serve(listener, app).await.unwrap();
|
axum::serve(listener, app).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_full() -> String {
|
|
||||||
get_address() + ":" + &get_port()
|
|
||||||
}
|
|
||||||
fn get_address() -> String {
|
|
||||||
String::from("0.0.0.0")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_port() -> String {
|
|
||||||
String::from("3000")
|
|
||||||
}
|
|
||||||
|
|
||||||
// basic handler that responds with a static string
|
|
||||||
async fn root() -> &'static str {
|
|
||||||
"Hello, World!"
|
|
||||||
}
|
|
||||||
|
11
src/models/common.rs
Normal file
11
src/models/common.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct CreateUser {
|
||||||
|
pub username: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct User {
|
||||||
|
pub username: String,
|
||||||
|
}
|
1
src/models/mod.rs
Normal file
1
src/models/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod common;
|
Reference in New Issue
Block a user