Fix with rustfmt
[sockgit.git] / src / main.rs
index 2b11523..a783233 100644 (file)
@@ -1,22 +1,19 @@
-use std::io;
+use git2;
 use std::env;
-use std::path;
 use std::error;
-use git2;
+use std::io;
+use std::path;
 
-fn check_ip() -> Result<(), io::Error> {
-    match env::var("REMOTE_ADDR") {
-        Ok(remote_ip) => match env::var("WHITELIST_IP") {
-            Ok(whitelist_ip) => {
-                if remote_ip == whitelist_ip {
-                    Ok(())
-                } else {
-                    Err(io::Error::new(io::ErrorKind::ConnectionRefused, format!("Blocked connection from {}", remote_ip)))
-                }
-            }
-            Err(e) => Err(io::Error::new(io::ErrorKind::ConnectionRefused, e)),
-        }
-        Err(e) => Err(io::Error::new(io::ErrorKind::ConnectionRefused, e)),
+fn check_ip() -> Result<(), Box<dyn error::Error>> {
+    let remote_ip = env::var("REMOTE_ADDR")?;
+    let whitelist_ip = env::var("WHITELIST_IP")?;
+    if remote_ip == whitelist_ip {
+        Ok(())
+    } else {
+        Err(Box::new(io::Error::new(
+            io::ErrorKind::ConnectionRefused,
+            format!("Blocked connection from {}", remote_ip),
+        )))
     }
 }
 
@@ -40,17 +37,17 @@ fn main() -> Result<(), Box<dyn error::Error>> {
             let public_name = env::var("PUBLIC").unwrap();
             let public_path = env::var("PATH").unwrap();
             repo.remote(
-                &public_name, 
+                &public_name,
                 &format!(
-                    "{user}@{public}:{path}/{repo}.git", 
-                    user = public_user, 
-                    public = public_name, 
-                    path = public_path, 
+                    "{user}@{public}:{path}/{repo}.git",
+                    user = public_user,
+                    public = public_name,
+                    path = public_path,
                     repo = repo_name
-                    )
-                )?;
+                ),
+            )?;
             Ok(())
-        } 
-        Err(e) => Err(Box::new(e)),
+        }
+        Err(e) => Err(e),
     }
 }