| Crates.io | orion-accessor |
| lib.rs | orion-accessor |
| version | 0.5.4 |
| created_at | 2025-09-21 16:55:32.931446+00 |
| updated_at | 2025-09-21 16:55:32.931446+00 |
| description | Unified accessor layer for HTTP, Git, and local resources with redirect rules, proxy control, and env-aware templating. |
| homepage | |
| repository | https://github.com/galaxy-sec/orion-accessor |
| max_upload_size | |
| id | 1848953 |
| size | 445,425 |
一个Rust库,提供地址重定向、模板处理和变量扩展功能,专为现代开发工作流设计。
${VAR} 和 ${VAR:-default} 语法统一接口: 统一的地址访问抽象 (AddrAccessor)
多协议支持: HTTP(S)、Git、本地文件系统
健壮客户端: HTTP 访问在代理或超时配置错误时返回详细 AddrResult
Git 构建器: GitRepository 流式 API 支持分支/标签、环境令牌与凭据文件
创建 redirect-rules.yml:
enable: true
units:
- name: "github-mirror"
rules:
- pattern: "https://github.com/*"
target: "https://ghproxy.com/https://github.com/"
- pattern: "https://raw.githubusercontent.com/*"
target: "https://ghproxy.com/https://raw.githubusercontent.com/"
auth:
username: "${GITHUB_USER}"
password: "${GITHUB_TOKEN}"
use orion_accessor::addr::redirect::RedirectService;
// 从配置文件加载
let service = RedirectService::from_file("redirect-rules.yml")?;
// 重定向地址
let original = "https://github.com/user/repo";
if let Some(redirected) = service.redirect(original) {
println!("重定向到: {}", redirected);
}
// 从字符串加载配置
let config = r#"
enable: true
units:
- rules:
- pattern: "https://example.com/*"
target: "https://mirror.example.com/"
"#;
let service = RedirectService::from_str(config)?;
use orion_accessor::addr::{Address, GitRepository, Validate};
let repo = GitRepository::from("https://github.com/user/repo.git")
.with_branch("main")
.with_git_credentials();
repo.validate()?; // 校验配置是否完整
# 使用环境变量的高级配置
enable: true
units:
- name: "enterprise-proxy"
rules:
- pattern: "https://${INTERNAL_DOMAIN}/*"
target: "https://${PROXY_HOST}/${INTERNAL_PATH}/"
auth:
username: "${PROXY_USER:-admin}"
password: "${PROXY_PASS:-default123}"
# 运行所有测试
cargo test
# 运行特定模块测试
cargo test addr::redirect
贡献流程与代码规范请见 AGENTS.md
提交 PR 前执行 cargo fmt, cargo clippy --all-targets --all-features -- -D warnings, cargo test -- --test-threads=1
MIT License - 详见 LICENSE 文件