Skip to content

Commit

Permalink
Move filter.rs into src/filter/mod and start function into lib
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Cattermole <[email protected]>
  • Loading branch information
adam-cattermole committed Jan 16, 2025
1 parent 0da11dd commit ddfb7b0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
40 changes: 0 additions & 40 deletions src/filter.rs

This file was deleted.

3 changes: 3 additions & 0 deletions src/filter/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub(crate) mod kuadrant_filter;
pub(crate) mod operations;
pub(crate) mod root_context;
37 changes: 37 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,43 @@ mod runtime_action_set;
mod runtime_config;
mod service;

#[cfg_attr(
all(
target_arch = "wasm32",
target_vendor = "unknown",
target_os = "unknown"
),
export_name = "_start"
)]
#[cfg_attr(
not(all(
target_arch = "wasm32",
target_vendor = "unknown",
target_os = "unknown"
)),
allow(dead_code)
)]
// This is a C interface, so make it explicit in the fn signature (and avoid mangling)
extern "C" fn start() {
use crate::filter::root_context::FilterRoot;
use log::info;
use proxy_wasm::traits::RootContext;
use proxy_wasm::types::LogLevel;

proxy_wasm::set_log_level(LogLevel::Trace);
std::panic::set_hook(Box::new(|panic_info| {
proxy_wasm::hostcalls::log(LogLevel::Critical, &panic_info.to_string())
.expect("failed to log panic_info");
}));
proxy_wasm::set_root_context(|context_id| -> Box<dyn RootContext> {
info!("#{} set_root_context", context_id);
Box::new(FilterRoot {
context_id,
action_set_index: Default::default(),
})
});
}

#[cfg(test)]
mod tests {
use crate::envoy::{HeaderValue, RateLimitResponse, RateLimitResponse_Code};
Expand Down

0 comments on commit ddfb7b0

Please sign in to comment.