someone knows of a Salvo tutorial? #174
Replies: 12 comments 11 replies
-
There are two blog system build with salvo: |
Beta Was this translation helpful? Give feedback.
-
Make sure you are using rust version >= 1.64 |
Beta Was this translation helpful? Give feedback.
-
boy.. do i feel stupid.. This was indeed the problem! basicauth works flawless now! |
Beta Was this translation helpful? Give feedback.
-
unfortunatly, i seem to be unable to get the sqlx example to work. but when i use this example: https://pastebin.com/v9DmxnwA (which is an almost exact replica of the example) it returns an EMTY_RESPONSE, and the commandline shows this:
It seems that the req.query return None, regardless of what i try :( This works!
|
Beta Was this translation helpful? Give feedback.
-
this is much true :) so: params when multiple values, param when single value of wich you know the type, thats basicly it. |
Beta Was this translation helpful? Give feedback.
-
so now, i am trying to serve static content following: https://salvo.rs/book/middlewares/serve_static/ i added everything on this page, and the error i receive is:
|
Beta Was this translation helpful? Give feedback.
-
thank you :) i now have this:
where i would think static is the directory under the main project folder (so, next to the src folder) but this throws me an error 404. |
Beta Was this translation helpful? Give feedback.
-
Also, i bought you some coffee, did you see? :) can you contact me privately? I have some questions, and some money. But i rather not discuss it publicly yet! |
Beta Was this translation helpful? Give feedback.
-
so i have this: #[derive(Debug, Deserialize)]
pub struct LoginUser {
pub username: String,
pub password: String,
} and: #[handler]
pub async fn login(req: &mut Request, depot: &mut Depot, res: &mut Response) {
if req.method() == salvo::http::Method::POST {
// Get the username and password from the database
// If they are correct, get the user role and push it into the session for use everywhere.
// This will allow users to access information based on their role
let uname = req.form::<String>("username").await;
let upass = req.form::<String>("password").await;
let user = sqlx::query_as::<_, LoginUser>("select * from users where username = $1 AND password = $2");
}
else {
let loginpage = LoginTemplate {
text: "Please login!",
};
res.render(Text::Html(loginpage.render().unwrap()));
}
} but it wont compile because i get the error: 21 | let user = sqlx::query_as::<_, LoginUser>("select * from users where username = $1 AND password = $2");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'r> FromRow<'r, _>` is not implemented for `structs::general::LoginUser` |
Beta Was this translation helpful? Give feedback.
-
It's true that this is not a Salvo problem, however i already added FromRow, which gives out different errors :) Maybe i'm just not cut out to learn to program :) |
Beta Was this translation helpful? Give feedback.
-
ok, so now i have a different problem :-) code: #[handler]
pub async fn borg_postlogs(res: &mut Response, req: &mut Request) {
// POST incoming data to the database
#[derive(Deserialize, Debug)]
struct Data {
token: String,
date: String,
name: String,
hostname: String,
duration: String,
files: String,
compressed_size: String,
original_size: String,
repository_id: String,
backupdir: String,
}
let d = req.parse_json::<Data>();
let e = d.token;
res.render(Text::Html(e));
} error: Compiling unimatrix v0.1.0 (/home/sysop/rust-prod/UNIMATRIX)
error[E0609]: no field `token` on type `impl Future<Output = Result<borg::borg_postlogs::borg_postlogs::{closure#0}::Data, salvo::http::ParseError>>`
--> src/handlers/borg.rs:73:15
|
73 | let e = d.token;
| ^^^^^ field not found in `impl Future<Output = Result<borg::borg_postlogs::borg_postlogs::{closure#0}::Data, salvo::http::ParseError>>`
For more information about this error, try `rustc --explain E0609`.
error: could not compile `unimatrix` due to previous error if i'm to believe "rustc --explain E0609" everything should work? |
Beta Was this translation helpful? Give feedback.
-
oh thats what i had originally, but that doesnt help either. What i forgot was the .unwrap thingy :| |
Beta Was this translation helpful? Give feedback.
-
I am looking at all the examples, but mixing and matching them seems to give me more problems then i can handle.
Does someone know of a tutorial that uses Salvo to write a CRUD web app? What i am looking for is a basic cms-like idea that uses sessions, user logins with a database backend. I am trying to learn Rust, but its not going very fast, and i need something workable rather sooner then later.
I'm not very rich but i am willing to pay a bit if no such tutorial exists but someone is willing to make such a webapp. preferably with some comments in the code so i can then use it to build upon.
Beta Was this translation helpful? Give feedback.
All reactions