accept String or &str for ip_port and net_id

This commit is contained in:
glyph 2022-07-13 11:08:45 +01:00
parent 22d12f31ac
commit 2f347ee0d6
1 changed files with 10 additions and 6 deletions

View File

@ -53,15 +53,19 @@ impl Sbot {
/// Initiate a connection with an sbot instance. Define the IP address,
/// port and network key for the sbot, then retrieve the public key,
/// private key (secret) and identity from the `.ssb-go/secret` file.
pub async fn init(
pub async fn init<S, T>(
keystore: Keystore,
ip_port: Option<String>,
net_id: Option<String>,
) -> Result<Sbot, GolgiError> {
ip_port: Option<S>,
net_id: Option<T>,
) -> Result<Sbot, GolgiError>
where
S: Into<String>,
T: Into<String>,
{
let mut address = if ip_port.is_none() {
"127.0.0.1:8008".to_string()
} else {
ip_port.unwrap()
ip_port.unwrap().into()
};
if address.starts_with(':') {
@ -71,7 +75,7 @@ impl Sbot {
let network_id = if net_id.is_none() {
discovery::ssb_net_id()
} else {
auth::Key::from_slice(&hex::decode(net_id.unwrap()).unwrap()).unwrap()
auth::Key::from_slice(&hex::decode(net_id.unwrap().into()).unwrap()).unwrap()
};
let OwnedIdentity { pk, sk, id } = match keystore {