mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-30 23:08:40 +08:00
Path filter, and rate limiter for Consul
This commit is contained in:
29
src/utils/kuberconsul.rs
Normal file
29
src/utils/kuberconsul.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use crate::utils::structs::{InnerMap, ServiceMapping, UpstreamsDashMap};
|
||||
use dashmap::DashMap;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
|
||||
pub fn list_to_upstreams(lt: Option<DashMap<String, (Vec<InnerMap>, AtomicUsize)>>, upstreams: &UpstreamsDashMap, i: &ServiceMapping) {
|
||||
if let Some(list) = lt {
|
||||
match upstreams.get(&i.hostname.clone()) {
|
||||
Some(upstr) => {
|
||||
for (k, v) in list {
|
||||
upstr.value().insert(k, v);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
upstreams.insert(i.hostname.clone(), list);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn match_path(conf: &ServiceMapping, upstreams: &DashMap<String, (Vec<InnerMap>, AtomicUsize)>, values: Vec<InnerMap>) {
|
||||
match conf.path {
|
||||
Some(ref p) => {
|
||||
upstreams.insert(p.to_string(), (values, AtomicUsize::new(0)));
|
||||
}
|
||||
None => {
|
||||
upstreams.insert("/".to_string(), (values, AtomicUsize::new(0)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user