Add Serialize trait to configs (#99)

This commit is contained in:
Mostafa Abdelraouf
2022-07-28 17:42:04 -05:00
committed by GitHub
parent 14d4dc45f5
commit 8a06fc4047

View File

@@ -2,7 +2,7 @@
use arc_swap::ArcSwap; use arc_swap::ArcSwap;
use log::{error, info}; use log::{error, info};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use serde_derive::Deserialize; use serde_derive::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::hash::Hash; use std::hash::Hash;
use std::path::Path; use std::path::Path;
@@ -21,7 +21,7 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
static CONFIG: Lazy<ArcSwap<Config>> = Lazy::new(|| ArcSwap::from_pointee(Config::default())); static CONFIG: Lazy<ArcSwap<Config>> = Lazy::new(|| ArcSwap::from_pointee(Config::default()));
/// Server role: primary or replica. /// Server role: primary or replica.
#[derive(Clone, PartialEq, Deserialize, Hash, std::cmp::Eq, Debug, Copy)] #[derive(Clone, PartialEq, Serialize, Deserialize, Hash, std::cmp::Eq, Debug, Copy)]
pub enum Role { pub enum Role {
Primary, Primary,
Replica, Replica,
@@ -95,7 +95,7 @@ impl Address {
} }
/// PostgreSQL user. /// PostgreSQL user.
#[derive(Clone, PartialEq, Hash, std::cmp::Eq, Deserialize, Debug)] #[derive(Clone, PartialEq, Hash, std::cmp::Eq, Serialize, Deserialize, Debug)]
pub struct User { pub struct User {
pub username: String, pub username: String,
pub password: String, pub password: String,
@@ -113,7 +113,7 @@ impl Default for User {
} }
/// General configuration. /// General configuration.
#[derive(Deserialize, Debug, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct General { pub struct General {
pub host: String, pub host: String,
pub port: i16, pub port: i16,
@@ -143,7 +143,7 @@ impl Default for General {
} }
} }
} }
#[derive(Deserialize, Debug, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Pool { pub struct Pool {
pub pool_mode: String, pub pool_mode: String,
pub shards: HashMap<String, Shard>, pub shards: HashMap<String, Shard>,
@@ -168,7 +168,7 @@ impl Default for Pool {
} }
/// Shard configuration. /// Shard configuration.
#[derive(Deserialize, Debug, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Shard { pub struct Shard {
pub database: String, pub database: String,
pub servers: Vec<(String, u16, String)>, pub servers: Vec<(String, u16, String)>,
@@ -188,7 +188,7 @@ fn default_path() -> String {
} }
/// Configuration wrapper. /// Configuration wrapper.
#[derive(Deserialize, Debug, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Config { pub struct Config {
#[serde(default = "default_path")] #[serde(default = "default_path")]
pub path: String, pub path: String,