Skip to content

Commit

Permalink
feat: Add: 1.Environment trait & config reader; 2.Omiga default const…
Browse files Browse the repository at this point in the history
…ants.

Signed-off-by: photowey <[email protected]>
  • Loading branch information
photowey committed Jul 9, 2024
1 parent 78c5546 commit 5010af3
Show file tree
Hide file tree
Showing 17 changed files with 715 additions and 9 deletions.
15 changes: 14 additions & 1 deletion crates/core/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,17 @@
// ----------------------------------------------------------------

pub const SIGMA_VERSION: &str = "0.1.0";
pub const SIGMA_CORE_PROFILE_ACTIVES: &str = "default";
pub const SIGMA_CORE_PROFILE_ACTIVES_DEFAULT: &str = "default";

// ----------------------------------------------------------------

// omiga.toml | omiga-dev.toml ...
pub const SIGMA_CORE_CONFIG_FILE_NAME_DEFAULT: &str = "omiga";
// toml* | yml/yaml | json | properties | ini | ...
pub const SIGMA_CORE_CONFIG_FILE_SUFFIX_DEFAULT: &str = "toml";
pub const SIGMA_CORE_CONFIG_FILE_SEARCH_PATHS_DEFAULT: &str = ".,configs,resources";

// ----------------------------------------------------------------

/// 9320: A dream moment for Manchester City's forward `Agüero`.
pub const SIGMA_WEB_SERVER_PORT_DEFAULT: u32 = 9320;
54 changes: 54 additions & 0 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright © 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// error

// ----------------------------------------------------------------

use std::error::Error;
use std::fmt;

#[allow(dead_code)] // tmp
#[derive(Debug, PartialEq)]
pub enum OmigaError {
Runtime(String),
IO(String),
Database(String),
Business(String),
Unknown(String),
}

impl fmt::Display for OmigaError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
OmigaError::Runtime(message) => {
write!(f, "Omiga: runtime error, message:[{}]", message)
}
OmigaError::IO(message) => write!(f, "Omiga: I/O error, message:[{}]", message),
OmigaError::Database(message) => {
write!(f, "Omiga: database error, message:[{}]", message)
}
OmigaError::Business(message) => {
write!(f, "Omiga: business error, message:[{}]", message)
}
OmigaError::Unknown(message) => {
write!(f, "Omiga: unknown error, message:[{}]", message)
}
}
}
}

impl Error for OmigaError {}
1 change: 1 addition & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
// ----------------------------------------------------------------

pub mod constants;
mod error;
1 change: 1 addition & 0 deletions crates/env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
chrono = "0.4"
7 changes: 6 additions & 1 deletion crates/env/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# `env`
# `env`

The core functionality is inspired by [configer](https://github.com/photowey/configer), and is mainly a migration to
adapt to the `omiga` project.

>
22 changes: 22 additions & 0 deletions crates/env/src/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright © 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// core

// ------------------------------------------------------------

pub mod domain;
pub mod error;
Loading

0 comments on commit 5010af3

Please sign in to comment.