Skip to content

Commit

Permalink
fix linker bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vxcall committed Sep 2, 2024
1 parent fc0820c commit 1e9b189
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 52 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/mold"]
7 changes: 4 additions & 3 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ RUN cargo install cargo-watch

RUN rustup component add rustfmt

RUN curl -L https://github.com/rui314/mold/releases/download/v2.33.0/mold-2.33.0-x86_64-linux.tar.gz -o mold-2.33.0-x86_64-linux.tar.gz \
&& tar -zxvf mold-2.33.0-x86_64-linux.tar.gz \
&& cd mold-2.33.0-x86_64-linux \
RUN curl -L https://github.com/rui314/mold/releases/download/v2.30.0/mold-2.30.0-x86_64-linux.tar.gz -o mold-2.30.0-x86_64-linux.tar.gz \
&& tar -zxvf mold-2.30.0-x86_64-linux.tar.gz \
&& cd mold-2.30.0-x86_64-linux \
&& cp -r bin/* /usr/local/bin/ \
&& cp -r lib/* /usr/local/lib/ \
&& ldconfig

WORKDIR /app

COPY .cargo/config.toml ./.cargo/config.toml
COPY Cargo.toml Cargo.lock ./
COPY src ./src
COPY .env ./
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ async fn main() -> Result<()> {
std::env::set_var("RUST_LOG", "actix_web=info");
}

println!("about to init env");
println!("[+] about to init env");
dotenv::dotenv().ok();
env_logger::init();

println!("env initialized succesfully");
println!("[+] env initialized succesfully");
let address = (utils::environment_variables::ADDRESS).clone();
let port = (utils::environment_variables::PORT).clone();

Expand All @@ -48,9 +48,9 @@ async fn main() -> Result<()> {
let shared_config = aws_config::load_from_env().await;
let dynamo_client = Arc::new(Client::new(&shared_config));

println!("dynamodb setup done");
println!("[+] dynamodb setup done");

println!("about to fire up web server!");
println!("[+] server start listening...");

HttpServer::new(move || {
App::new()
Expand Down
2 changes: 1 addition & 1 deletion src/routes/handlers/auth_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::utils::{
app_state::{self, AppState},
global_variables::DYNAMO_DB_TABLE_NAME,
jwt::{add_to_blacklist, encode_jwt},
models::User,
user::get_user_from_email,
user::User,
};
use actix_web::{post, web, HttpRequest};
use anyhow::Result;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/handlers/user_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::utils::{
app_state,
global_variables::DYNAMO_DB_TABLE_NAME,
jwt::Claims,
models::User,
user::User,
};

#[derive(serde::Serialize, serde::Deserialize)]
Expand Down
1 change: 0 additions & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ pub mod app_state;
pub mod environment_variables;
pub mod global_variables;
pub mod jwt;
pub mod models;
pub mod user;
41 changes: 0 additions & 41 deletions src/utils/models.rs

This file was deleted.

42 changes: 41 additions & 1 deletion src/utils/user.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use anyhow::Result;
use std::collections::HashMap;

use anyhow::anyhow;
use aws_sdk_dynamodb::types::AttributeValue;
use std::sync::Arc;

use aws_sdk_dynamodb::{operation::query::QueryOutput, types::AttributeValue, Client};
use aws_sdk_dynamodb::{operation::query::QueryOutput, Client};

use super::global_variables::DYNAMO_DB_TABLE_NAME;

Expand All @@ -21,3 +25,39 @@ pub(crate) async fn get_user_from_email(
.await
.map_err(anyhow::Error::from)
}

#[derive(Debug)]
pub(crate) struct User {
pub(crate) id: String,
pub(crate) name: String,
pub(crate) email: String,
#[allow(dead_code)]
pub(crate) password: String,
}

impl User {
pub(crate) fn from_item(item: &HashMap<String, AttributeValue>) -> Result<Self> {
Ok(User {
id: item
.get("id")
.and_then(|v| v.as_s().ok())
.ok_or_else(|| anyhow!("Missing id"))?
.to_string(),
name: item
.get("name")
.and_then(|v| v.as_s().ok())
.ok_or_else(|| anyhow!("Missing name"))?
.to_string(),
email: item
.get("email")
.and_then(|v| v.as_s().ok())
.ok_or_else(|| anyhow!("Missing email"))?
.to_string(),
password: item
.get("password")
.and_then(|v| v.as_s().ok())
.ok_or_else(|| anyhow!("Missing password"))?
.to_string(),
})
}
}

0 comments on commit 1e9b189

Please sign in to comment.