-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adriano Santos
committed
Feb 12, 2023
1 parent
31fea3e
commit 6f3bbdc
Showing
10 changed files
with
95 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
extern crate prost_types; | ||
extern crate tokio; | ||
|
||
mod joe; | ||
|
||
use spawn_rs::spawn::Spawn; | ||
|
||
fn main() { | ||
#[tokio::main] | ||
async fn main() { | ||
Spawn::new() | ||
.system("spawn-system".to_string()) | ||
.port(8091) | ||
.add_actor(Box::new(joe::Joe {})) | ||
.start(); | ||
.start() | ||
.await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
pub mod v1 { | ||
use crate::actor::Actor; | ||
|
||
use actix_web::{post, web::Data, HttpRequest, Responder}; | ||
|
||
#[post("/actions")] | ||
pub async fn handle(_data: Data<Vec<Box<dyn Actor>>>, _req: HttpRequest) -> impl Responder { | ||
"Hello World from v1 API!" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod callback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,79 @@ | ||
use actor::Actor; | ||
use crate::actor::Actor; | ||
use crate::handler::callback; | ||
|
||
use std::io::Result; | ||
|
||
use actix_web::{ | ||
middleware, | ||
web::{self}, | ||
App, HttpServer, | ||
}; | ||
|
||
pub struct Spawn { | ||
system: String, | ||
actor: Vec<Box<dyn Actor>>, | ||
actors: Vec<Box<dyn Actor>>, | ||
server_port: u16, | ||
} | ||
|
||
impl Default for Spawn { | ||
fn default() -> Spawn { | ||
Spawn { | ||
actor: Vec::new(), | ||
actors: Vec::new(), | ||
server_port: 8091, | ||
system: String::from(""), | ||
} | ||
} | ||
} | ||
|
||
impl Spawn { | ||
pub fn new() -> Self { | ||
Default::default() | ||
pub fn add_actor(&mut self, actor: Box<dyn Actor>) -> &mut Spawn { | ||
self.actors.push(actor); | ||
self | ||
} | ||
|
||
pub fn system(&mut self, system_name: String) -> &mut Spawn { | ||
self.system = system_name; | ||
self | ||
pub fn get_actors(&mut self) -> &mut Vec<Box<dyn Actor>> { | ||
&mut self.actors | ||
} | ||
|
||
pub fn get_port(&mut self) -> u16 { | ||
self.server_port | ||
} | ||
|
||
pub fn get_system(&mut self) -> &mut String { | ||
&mut self.system | ||
} | ||
|
||
pub fn new() -> Self { | ||
Default::default() | ||
} | ||
|
||
pub fn port(&mut self, server_port: u16) -> &mut Spawn { | ||
self.server_port = server_port; | ||
self | ||
} | ||
|
||
pub fn add_actor(&mut self, actor: Box<dyn Actor>) -> &mut Spawn { | ||
self.actor.push(actor); | ||
pub fn system(&mut self, system_name: String) -> &mut Spawn { | ||
self.system = system_name; | ||
self | ||
} | ||
|
||
pub fn start(&mut self) {} | ||
pub async fn start(&mut self) -> Result<()> { | ||
let server = HttpServer::new(move || { | ||
App::new() | ||
//.app_data(self.get_actors()) | ||
.wrap(middleware::Logger::default()) | ||
.configure(Self::config) | ||
}) | ||
.bind(("127.0.0.1", self.get_port()))? | ||
.run(); | ||
|
||
//future::join(server, another_func()).await; | ||
server.await | ||
} | ||
|
||
fn config(conf: &mut web::ServiceConfig) { | ||
let scope = web::scope("/api/v1/actors").service(callback::v1::handle); | ||
|
||
conf.service(scope); | ||
} | ||
} |