From f030a4075b7bc742c1db60400bb3188a8ebbfd59 Mon Sep 17 00:00:00 2001 From: nkanaev Date: Mon, 4 Jul 2022 16:03:50 +0100 Subject: [PATCH] refactoring --- src/main.go | 17 +++++++++++++++++ src/{password_test.go => main_test.go} | 0 src/password.go | 23 ----------------------- 3 files changed, 17 insertions(+), 23 deletions(-) rename src/{password_test.go => main_test.go} (100%) delete mode 100644 src/password.go diff --git a/src/main.go b/src/main.go index 93f0197..33cdc28 100644 --- a/src/main.go +++ b/src/main.go @@ -1,8 +1,10 @@ package main import ( + "bufio" "flag" "fmt" + "io" "log" "os" "path/filepath" @@ -27,6 +29,21 @@ func opt(envVar, defaultValue string) string { return defaultValue } +func parseAuthfile(authfile io.Reader) (username, password string, err error) { + scanner := bufio.NewScanner(authfile) + for scanner.Scan() { + line := scanner.Text() + parts := strings.SplitN(line, ":", 2) + if len(parts) != 2 { + return "", "", fmt.Errorf("wrong syntax (expected `username:password`)") + } + username = parts[0] + password = parts[1] + break + } + return username, password, nil +} + func main() { platform.FixConsoleIfNeeded() diff --git a/src/password_test.go b/src/main_test.go similarity index 100% rename from src/password_test.go rename to src/main_test.go diff --git a/src/password.go b/src/password.go deleted file mode 100644 index 8bfc36a..0000000 --- a/src/password.go +++ /dev/null @@ -1,23 +0,0 @@ -package main - -import ( - "bufio" - "fmt" - "io" - "strings" -) - -func parseAuthfile(authfile io.Reader) (username, password string, err error) { - scanner := bufio.NewScanner(authfile) - for scanner.Scan() { - line := scanner.Text() - parts := strings.SplitN(line, ":", 2) - if len(parts) != 2 { - return "", "", fmt.Errorf("wrong syntax (expected `username:password`)") - } - username = parts[0] - password = parts[1] - break - } - return username, password, nil -}