mirror of
https://github.com/actix/examples
synced 2024-11-23 14:31:07 +01:00
group imports
This commit is contained in:
parent
4b801ba222
commit
a64e21ee6e
@ -1,8 +1,8 @@
|
||||
use casbin::{CoreApi, DefaultModel, Enforcer, FileAdapter, RbacApi};
|
||||
use std::io;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use actix_web::{middleware, web, App, HttpRequest, HttpResponse, HttpServer};
|
||||
use casbin::{CoreApi, DefaultModel, Enforcer, FileAdapter, RbacApi};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
/// simple handle
|
||||
async fn success(enforcer: web::Data<RwLock<Enforcer>>, req: HttpRequest) -> HttpResponse {
|
||||
|
@ -100,7 +100,6 @@ async fn main() -> std::io::Result<()> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use actix_web::{
|
||||
middleware,
|
||||
web::{get, post, resource},
|
||||
@ -108,6 +107,8 @@ mod test {
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_workflow() {
|
||||
let private_key = actix_web::cookie::Key::generate();
|
||||
|
@ -1,10 +1,9 @@
|
||||
// email_service.rs
|
||||
use crate::errors::ServiceError;
|
||||
use crate::models::Invitation;
|
||||
use sparkpost::transmission::{
|
||||
EmailAddress, Message, Options, Recipient, Transmission, TransmissionResponse,
|
||||
};
|
||||
|
||||
use crate::{errors::ServiceError, models::Invitation};
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref API_KEY: String = std::env::var("SPARKPOST_API_KEY").expect("SPARKPOST_API_KEY must be set");
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
use std::convert::From;
|
||||
|
||||
use actix_web::{error::ResponseError, HttpResponse};
|
||||
use derive_more::Display;
|
||||
use diesel::result::{DatabaseErrorKind, Error as DBError};
|
||||
use std::convert::From;
|
||||
use uuid::Error as ParseError;
|
||||
|
||||
#[derive(Debug, Display)]
|
||||
|
@ -1,7 +1,8 @@
|
||||
use super::schema::*;
|
||||
use diesel::{r2d2::ConnectionManager, PgConnection};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::schema::*;
|
||||
|
||||
// type alias to use in multiple places
|
||||
pub type Pool = r2d2::Pool<ConnectionManager<PgConnection>>;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::errors::ServiceError;
|
||||
use argon2::{self, Config};
|
||||
|
||||
use crate::errors::ServiceError;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref SECRET_KEY: String = std::env::var("SECRET_KEY").unwrap_or_else(|_| "0123".repeat(8));
|
||||
}
|
||||
|
@ -24,11 +24,12 @@ async fn main() -> std::io::Result<()> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use actix_web::body::to_bytes;
|
||||
use actix_web::dev::Service;
|
||||
use actix_web::{http, test, web, App, Error};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_index() -> Result<(), Error> {
|
||||
let app = App::new().route("/", web::get().to(index));
|
||||
|
@ -1,5 +1,4 @@
|
||||
use actix_web::{middleware, App, HttpServer};
|
||||
|
||||
use nested_routing::app_config::config_app;
|
||||
|
||||
#[actix_web::main]
|
||||
|
@ -20,13 +20,14 @@ pub async fn remove_product(_id: web::Path<String>) -> Result<HttpResponse, Erro
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::app_config::config_app;
|
||||
use actix_web::dev::Service;
|
||||
use actix_web::{
|
||||
dev::Service,
|
||||
http::{header, StatusCode},
|
||||
test, App,
|
||||
};
|
||||
|
||||
use crate::app_config::config_app;
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_add_product() {
|
||||
let app = test::init_service(App::new().configure(config_app)).await;
|
||||
|
@ -1,6 +1,5 @@
|
||||
use actix_web::web::Data;
|
||||
use actix_web::{get, App, HttpServer};
|
||||
|
||||
use redis_tang::{Builder, Pool, RedisManager};
|
||||
|
||||
#[actix_web::main]
|
||||
|
@ -5,9 +5,8 @@ mod model;
|
||||
mod test;
|
||||
|
||||
use actix_web::{get, post, web, App, HttpResponse, HttpServer};
|
||||
use mongodb::{bson::doc, options::IndexOptions, Client, Collection, IndexModel};
|
||||
|
||||
use model::User;
|
||||
use mongodb::{bson::doc, options::IndexOptions, Client, Collection, IndexModel};
|
||||
|
||||
const DB_NAME: &str = "myApp";
|
||||
const COLL_NAME: &str = "users";
|
||||
|
@ -51,10 +51,11 @@ mod errors {
|
||||
}
|
||||
|
||||
mod db {
|
||||
use crate::{errors::MyError, models::User};
|
||||
use deadpool_postgres::Client;
|
||||
use tokio_pg_mapper::FromTokioPostgresRow;
|
||||
|
||||
use crate::{errors::MyError, models::User};
|
||||
|
||||
pub async fn add_user(client: &Client, user_info: User) -> Result<User, MyError> {
|
||||
let _stmt = include_str!("../sql/add_user.sql");
|
||||
let _stmt = _stmt.replace("$table_fields", &User::sql_table_fields());
|
||||
@ -80,10 +81,11 @@ mod db {
|
||||
}
|
||||
|
||||
mod handlers {
|
||||
use crate::{db, errors::MyError, models::User};
|
||||
use actix_web::{web, Error, HttpResponse};
|
||||
use deadpool_postgres::{Client, Pool};
|
||||
|
||||
use crate::{db, errors::MyError, models::User};
|
||||
|
||||
pub async fn add_user(
|
||||
user: web::Json<User>,
|
||||
db_pool: web::Data<Pool>,
|
||||
@ -98,13 +100,14 @@ mod handlers {
|
||||
}
|
||||
}
|
||||
|
||||
use crate::config::ExampleConfig;
|
||||
use ::config::Config;
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use dotenv::dotenv;
|
||||
use handlers::add_user;
|
||||
use tokio_postgres::NoTls;
|
||||
|
||||
use crate::config::ExampleConfig;
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
dotenv().ok();
|
||||
|
@ -1,7 +1,8 @@
|
||||
use std::{thread::sleep, time::Duration};
|
||||
|
||||
use actix_web::{error, web, Error};
|
||||
use rusqlite::Statement;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{thread::sleep, time::Duration};
|
||||
|
||||
pub type Pool = r2d2::Pool<r2d2_sqlite::SqliteConnectionManager>;
|
||||
pub type Connection = r2d2::PooledConnection<r2d2_sqlite::SqliteConnectionManager>;
|
||||
|
@ -1,6 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use actix_web::{middleware, web, App, HttpRequest, HttpResponse, HttpServer, Responder, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
struct AppState {
|
||||
foo: String,
|
||||
@ -71,13 +70,14 @@ async fn handle_post_3(req: HttpRequest, params: web::Form<MyParams>) -> impl Re
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use actix_web::body::to_bytes;
|
||||
use actix_web::dev::{Service, ServiceResponse};
|
||||
use actix_web::http::{header::HeaderValue, header::CONTENT_TYPE, StatusCode};
|
||||
use actix_web::test::{self, TestRequest};
|
||||
use actix_web::web::{Bytes, Form};
|
||||
|
||||
use super::*;
|
||||
|
||||
trait BodyTest {
|
||||
fn as_str(&self) -> &str;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::io::Read as _;
|
||||
|
||||
use rusoto_core::Region;
|
||||
use rusoto_s3::S3;
|
||||
use rusoto_s3::{DeleteObjectRequest, PutObjectRequest, S3Client};
|
||||
use std::io::Read;
|
||||
use rusoto_s3::{DeleteObjectRequest, PutObjectRequest, S3Client, S3};
|
||||
|
||||
pub struct Client {
|
||||
#[allow(dead_code)]
|
||||
|
@ -1,10 +1,11 @@
|
||||
use crate::utils::s3::Client;
|
||||
use std::{convert::From, io::Write};
|
||||
|
||||
use actix_multipart::{Field, Multipart};
|
||||
use actix_web::{web, web::Bytes, Error};
|
||||
use futures_util::StreamExt as _;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::convert::From;
|
||||
use std::io::Write;
|
||||
|
||||
use crate::utils::s3::Client;
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||
pub struct UploadFile {
|
||||
|
@ -3,11 +3,12 @@ use juniper::{
|
||||
};
|
||||
use mysql::{from_row, params, Error as DBError, Row};
|
||||
|
||||
use super::{
|
||||
product::{Product, ProductInput},
|
||||
user::{User, UserInput},
|
||||
};
|
||||
use crate::db::Pool;
|
||||
|
||||
use super::product::{Product, ProductInput};
|
||||
use super::user::{User, UserInput};
|
||||
|
||||
pub struct Context {
|
||||
pub dbpool: Pool,
|
||||
}
|
||||
|
@ -84,10 +84,9 @@ async fn main() -> std::io::Result<()> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::{body::to_bytes, dev::Service, http, test, web, App};
|
||||
|
||||
use super::*;
|
||||
use actix_web::body::to_bytes;
|
||||
use actix_web::dev::Service;
|
||||
use actix_web::{http, test, web, App};
|
||||
|
||||
#[actix_web::test]
|
||||
async fn test_index() {
|
||||
|
@ -1 +1,2 @@
|
||||
reorder_imports = true
|
||||
group_imports = "StdExternalCrate"
|
||||
|
@ -1,6 +1,7 @@
|
||||
use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer};
|
||||
use std::{sync::mpsc, thread};
|
||||
|
||||
use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer};
|
||||
|
||||
#[get("/hello")]
|
||||
async fn hello() -> &'static str {
|
||||
"Hello world!"
|
||||
|
@ -1,12 +1,15 @@
|
||||
use actix_web::body::BoxBody;
|
||||
use actix_web::dev::ServiceResponse;
|
||||
use actix_web::http::header::ContentType;
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::middleware::{ErrorHandlerResponse, ErrorHandlers};
|
||||
use actix_web::{get, web, App, HttpResponse, HttpServer, Result};
|
||||
use std::io;
|
||||
|
||||
use actix_web::{
|
||||
body::BoxBody,
|
||||
dev::ServiceResponse,
|
||||
get,
|
||||
http::{header::ContentType, StatusCode},
|
||||
middleware::{ErrorHandlerResponse, ErrorHandlers},
|
||||
web, App, HttpResponse, HttpServer, Result,
|
||||
};
|
||||
use handlebars::Handlebars;
|
||||
use serde_json::json;
|
||||
use std::io;
|
||||
|
||||
// Macro documentation can be found in the actix_web_codegen crate
|
||||
#[get("/")]
|
||||
|
@ -1,10 +1,13 @@
|
||||
use actix_web::body::BoxBody;
|
||||
use actix_web::dev::ServiceResponse;
|
||||
use actix_web::http::header::ContentType;
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::middleware::{ErrorHandlerResponse, ErrorHandlers};
|
||||
use actix_web::{error, middleware, web, App, Error, HttpResponse, HttpServer, Result};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use actix_web::{
|
||||
body::BoxBody,
|
||||
dev::ServiceResponse,
|
||||
error,
|
||||
http::{header::ContentType, StatusCode},
|
||||
middleware::{self, ErrorHandlerResponse, ErrorHandlers},
|
||||
web, App, Error, HttpResponse, HttpServer, Result,
|
||||
};
|
||||
use tera::Tera;
|
||||
|
||||
// store tera template in application state
|
||||
|
@ -2,9 +2,10 @@
|
||||
//! And manages available rooms. Peers send messages to other peers in same
|
||||
//! room through `ChatServer`.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use actix::prelude::*;
|
||||
use rand::{self, rngs::ThreadRng, Rng};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use crate::session;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user