您最多能選擇 25 個主題
主題必須以字母或數字為開頭,可包含連接號「-」且最長為 35 個字元。
KitaitiMakoto
51b49e8629
Reviewed-on: #13 |
2 年前 | |
---|---|---|
src | 2 年前 | |
.gitattributes | 4 年前 | |
.gitignore | 5 年前 | |
.travis.yml | 4 年前 | |
Cargo.toml | 2 年前 | |
LICENSE | 4 年前 | |
README.md | 4 年前 | |
coverage.sh | 5 年前 |
README.md
WebFinger
A crate to help you fetch and serve WebFinger resources.
Examples
Fetching a resource:
use webfinger::resolve;
fn main() {
let res = resolve("acct:test@example.org", true).expect("Error while fetching resource");
println!("Places to get more informations about {}:", res.subject);
for link in res.links.into_iter() {
println!("- {}", link.href);
}
}
Serving resources:
use webfinger::Resolver;
pub struct MyResolver;
impl Resolver<DatabaseConnection> for MyResolver {
fn instance_domain<'a>() -> &'a str {
"instance.tld"
}
fn find(acct: String, db: DatabaseConnection) -> Result<Webfinger, ResolverError> {
if let Some(user) = db.find_user_by_name(acct) {
Ok(Webfinger {
subject: acct.clone(),
aliases: vec![acct.clone()],
links: vec![
Link {
rel: "http://webfinger.net/rel/profile-page".to_string(),
mime_type: None,
href: user.profile_url()
}
]
})
} else {
Err(ResolverError::NotFound)
}
}
}
fn main() {
// Start a web server and map /.well-known/webfinger to a function calling MyResolver::endpoint
}