detector 0.5.4

A set of types for service registration and discovery.
Documentation
use serde::{Deserialize, Serialize};

#[derive(Copy, Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub enum ServiceState {
    /// 状态服(有限度的被分发到固定实例)
    Stateful = 0,
    /// 无状态服(可被分发到任意实例)
    Stateless = 1,
    /// 固定服(通过编号被分发到固定实例)
    Fixed = 2,
}

impl ServiceState {
    pub fn stateful(&self) -> bool {
        match self {
            ServiceState::Stateful => true,
            _ => false,
        }
    }

    pub fn stateless(&self) -> bool {
        match self {
            ServiceState::Stateless => true,
            _ => false,
        }
    }

    pub fn fixed(&self) -> bool {
        match self {
            ServiceState::Fixed => true,
            _ => false,
        }
    }
}

/// 负载均衡
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub enum Strategy {
    Hash = 0,
    ConsistentHash = 1,
    RoundRobin = 2,
}

/// 转发规则
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DestinationRule {
    /// 通过路径来转发
    Path(Strategy),
    /// 通过头部key来转发
    Header(String, Strategy)
}