From 96f62b851343043c93ca5dbd9d2724b5b247a33c Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 24 Nov 2022 20:53:07 +0100 Subject: [PATCH] Add missing file --- examples/federation/utils.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 examples/federation/utils.rs diff --git a/examples/federation/utils.rs b/examples/federation/utils.rs new file mode 100644 index 0000000..87c421e --- /dev/null +++ b/examples/federation/utils.rs @@ -0,0 +1,13 @@ +use rand::{distributions::Alphanumeric, thread_rng, Rng}; +use url::{ParseError, Url}; + +/// Just generate random url as object id. In a real project, you probably want to use +/// an url which contains the database id for easy retrieval (or store the random id in db). +pub fn generate_object_id(hostname: &str) -> Result { + let id: String = thread_rng() + .sample_iter(&Alphanumeric) + .take(7) + .map(char::from) + .collect(); + Url::parse(&format!("http://{}/objects/{}", hostname, id)) +}