-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ add individual config to services
- Loading branch information
1 parent
e22afe0
commit 5a3d180
Showing
19 changed files
with
496 additions
and
10 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::net::SocketAddr; | ||
|
||
#[derive(Debug, PartialEq)] | ||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] | ||
pub struct GrpcConfig { | ||
pub listen: Vec<SocketAddr>, | ||
} |
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,7 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#[derive(Debug, Clone)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub struct RabbitMqConfig { | ||
pub uri: String, | ||
} |
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 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::net::SocketAddr; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Deserialize, PartialEq, Serialize)] | ||
pub struct RestConfig { | ||
pub listen: Vec<SocketAddr>, | ||
} |
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,16 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
[package] | ||
name = "rsjudge-traits" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
async-trait = "0.1.80" | ||
serde = "1.0.198" |
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,7 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pub trait Judger { | ||
type Result; | ||
fn accept_languages(&self) -> Vec<String>; | ||
fn judge(&self, lang: &str, code: &str, input: &str) -> Self::Result; | ||
} |
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,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
mod judger; | ||
mod service; | ||
|
||
pub use crate::{judger::Judger, service::Service}; |
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,19 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use async_trait::async_trait; | ||
use serde::de::DeserializeOwned; | ||
|
||
use crate::Judger; | ||
|
||
#[async_trait] | ||
pub trait Service<J, C> | ||
where | ||
J: Judger, | ||
C: Config, | ||
{ | ||
type Result; | ||
async fn startup(&mut self, judger: J, config: C) -> Self::Result; | ||
async fn shutdown(&mut self); | ||
} | ||
|
||
pub trait Config: DeserializeOwned {} |
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,75 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::collections::HashMap; | ||
|
||
#[cfg(feature = "grpc")] | ||
use rsjudge_grpc::config::GrpcConfig; | ||
#[cfg(feature = "rabbitmq")] | ||
use rsjudge_rabbitmq::config::RabbitMqConfig; | ||
#[cfg(feature = "rest")] | ||
use rsjudge_rest::config::RestConfig; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct Config { | ||
pub executors: HashMap<String, Executor>, | ||
pub services: Services, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct Executor { | ||
// TODO: Add fields here | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct Services { | ||
#[cfg(feature = "grpc")] | ||
pub grpc: GrpcConfig, | ||
#[cfg(feature = "rabbitmq")] | ||
pub rabbitmq: RabbitMqConfig, | ||
#[cfg(feature = "rest")] | ||
pub rest: RestConfig, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[cfg(any(feature = "grpc", feature = "rest"))] | ||
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6}; | ||
|
||
#[cfg(feature = "grpc")] | ||
use rsjudge_grpc::config::GrpcConfig; | ||
#[cfg(feature = "rabbitmq")] | ||
use rsjudge_rabbitmq::config::RabbitMqConfig; | ||
#[cfg(feature = "rest")] | ||
use rsjudge_rest::config::RestConfig; | ||
|
||
use crate::config::Services; | ||
|
||
#[test] | ||
fn test_config() -> anyhow::Result<()> { | ||
println!( | ||
"{}", | ||
toml::to_string_pretty(&Services { | ||
#[cfg(feature = "grpc")] | ||
grpc: GrpcConfig { | ||
listen: vec![ | ||
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 50051)), | ||
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, 50051, 0, 0)) | ||
] | ||
}, | ||
#[cfg(feature = "rest")] | ||
rest: RestConfig { | ||
listen: vec![ | ||
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 80)), | ||
SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, 80, 0, 0)) | ||
] | ||
}, | ||
#[cfg(feature = "rabbitmq")] | ||
rabbitmq: RabbitMqConfig { | ||
uri: "amqp://user:bitnami@localhost".to_owned() | ||
}, | ||
})? | ||
); | ||
Ok(()) | ||
} | ||
} |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
[grpc] | ||
listen = [ | ||
"0.0.0.0:50051", | ||
"[::]:50051", | ||
] | ||
|
||
[rest] | ||
listen = [ | ||
"0.0.0.0:80", | ||
"[::]:80", | ||
] | ||
|
||
[rabbitmq] | ||
uri = "amqp://user:bitnami@localhost" |