aiway_protocol/context/
route.rs1use crate::gateway::plugin::ConfiguredPlugin;
2use serde::{Deserialize, Serialize};
3use std::collections::BTreeMap;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
6pub struct Route {
7 pub name: String,
9 pub host: String,
12 pub path: String,
16 pub match_paths: Vec<String>,
21 pub service: String,
23 pub methods: Vec<String>,
27 #[serde(alias = "header_condition", alias = "header-condition")]
31 pub header: BTreeMap<String, String>,
32 #[serde(alias = "query_condition", alias = "query-condition")]
36 pub query: BTreeMap<String, String>,
37 #[serde(default = "Vec::default", alias = "pre_filters", alias = "pre-filters")]
39 pub plugins: Vec<ConfiguredPlugin>,
40 #[serde(default = "bool::default", alias = "is_auth", alias = "is-auth")]
44 pub is_auth: bool,
45 pub auth_white_list: Vec<String>,
47}
48
49impl Route {
50 pub fn get_service(&self) -> &String {
51 &self.service
52 }
53
54 pub fn to_match_keys(&self) -> Vec<String> {
56 self.match_paths
57 .iter()
58 .map(|p| {
59 if self.host == "*" {
60 format!("{{host}}{}", p)
61 } else {
62 format!("{}{}", self.host, p)
63 }
64 })
65 .collect()
66 }
67}