Compare commits

...

3 Commits

Author SHA1 Message Date
Edward Shen 0f27cfb788
clippy 2023-01-13 00:29:42 -08:00
Edward Shen 768f944b36
Update deps 2023-01-13 00:18:00 -08:00
Edward Shen 1588deb073
Remove strip instructions 2022-06-02 23:36:33 -07:00
6 changed files with 352 additions and 333 deletions

627
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -13,14 +13,14 @@ exclude = ["/aux/"]
anyhow = "1"
arc-swap = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
axum = "0.5"
clap = { version = "3", features = ["wrap_help", "derive", "cargo"] }
axum = "0.6"
clap = { version = "4", features = ["wrap_help", "derive", "cargo"] }
dirs = "4"
handlebars = "4"
hotwatch = "0.4"
percent-encoding = "2"
serde = { version = "1", features = ["derive"] }
serde_yaml = "0.8"
serde_yaml = "0.9"
serde_json = "1"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

View File

@ -51,8 +51,7 @@ start bunbun as a daemon.
If you're looking to build a release binary, here are the steps I use:
1. `cargo build --release`
2. `strip target/release/bunbun`
3. `upx --lzma target/release/bunbun`
2. `upx --lzma target/release/bunbun`
LZMA provides the best level of compress for Rust binaries; it performs at the
same level as `upx --ultra-brute` without the time cost and [without breaking

View File

@ -18,7 +18,7 @@ const LARGE_FILE_SIZE_THRESHOLD: u64 = 100_000_000;
#[cfg(test)]
const LARGE_FILE_SIZE_THRESHOLD: u64 = 1_000_000;
#[derive(Deserialize, Debug, PartialEq)]
#[derive(Deserialize, Debug, PartialEq, Eq)]
pub struct Config {
pub bind_address: String,
pub public_address: String,
@ -26,7 +26,7 @@ pub struct Config {
pub groups: Vec<RouteGroup>,
}
#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)]
#[derive(Deserialize, Serialize, Debug, Eq, PartialEq, Clone)]
pub struct RouteGroup {
pub name: String,
pub description: Option<String>,
@ -35,7 +35,7 @@ pub struct RouteGroup {
pub routes: HashMap<String, Route>,
}
#[derive(Debug, PartialEq, Clone, Serialize)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize)]
pub struct Route {
pub route_type: RouteType,
pub path: String,
@ -211,7 +211,7 @@ fn get_route_type(path: &str) -> RouteType {
/// There exists two route types: an external path (e.g. a URL) or an internal
/// path (to a file).
#[derive(Debug, PartialEq, Clone, Serialize)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize)]
pub enum RouteType {
External,
Internal,
@ -288,7 +288,7 @@ pub fn get_config_data() -> Result<FileData, BunBunError> {
});
}
Err(e) => {
debug!("Tried to open a new file at '{location:?}' but failed due to error: {e}",)
debug!("Tried to open a new file at '{location:?}' but failed due to error: {e}");
}
}
}

View File

@ -57,10 +57,7 @@ async fn main() -> Result<()> {
.with(env_filter)
.init();
let conf_data = match opts.config {
Some(file_name) => load_custom_file(file_name),
None => get_config_data(),
}?;
let conf_data = opts.config.map_or_else(get_config_data, load_custom_file)?;
let conf = load_file(conf_data.file.try_clone()?, opts.large_config)?;
let state = Arc::from(ArcSwap::from_pointee(State {
@ -100,11 +97,10 @@ fn cache_routes(groups: Vec<RouteGroup>) -> HashMap<String, Route> {
for group in groups {
for (kw, dest) in group.routes {
// This function isn't called often enough to not be a performance issue.
match mapping.insert(kw.clone(), dest.clone()) {
None => trace!("Inserting {kw} into mapping."),
Some(old_value) => {
trace!("Overriding {kw} route from {old_value} to {dest}.");
}
if let Some(old_value) = mapping.insert(kw.clone(), dest.clone()) {
trace!("Overriding {kw} route from {old_value} to {dest}.");
} else {
trace!("Inserting {kw} into mapping.");
}
}
}

View File

@ -153,14 +153,11 @@ fn resolve_hop<'a>(
default_route: Option<&str>,
) -> RouteResolution<'a> {
let mut split_args = query.split_ascii_whitespace().peekable();
let maybe_route = {
match split_args.peek() {
Some(command) => routes.get(*command),
None => {
debug!("Found empty query, returning no route.");
return RouteResolution::Unresolved;
}
}
let maybe_route = if let Some(command) = split_args.peek() {
routes.get(*command)
} else {
debug!("Found empty query, returning no route.");
return RouteResolution::Unresolved;
};
let args = split_args.collect::<Vec<_>>();
@ -177,13 +174,11 @@ fn resolve_hop<'a>(
}
// Try resolving with the default route, if it exists
if let Some(route) = default_route {
if let Some(route) = routes.get(route) {
if check_route(route, arg_count) {
let args = args.join(" ");
debug!("Using default route {route} with args {args}");
return RouteResolution::Resolved { route, args };
}
if let Some(route) = default_route.and_then(|route| routes.get(route)) {
if check_route(route, arg_count) {
let args = args.join(" ");
debug!("Using default route {route} with args {args}");
return RouteResolution::Resolved { route, args };
}
}