refactoring

This commit is contained in:
nkanaev 2022-07-04 16:03:50 +01:00
parent c9dd977600
commit f030a4075b
3 changed files with 17 additions and 23 deletions

View File

@ -1,8 +1,10 @@
package main package main
import ( import (
"bufio"
"flag" "flag"
"fmt" "fmt"
"io"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -27,6 +29,21 @@ func opt(envVar, defaultValue string) string {
return defaultValue 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() { func main() {
platform.FixConsoleIfNeeded() platform.FixConsoleIfNeeded()

View File

@ -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
}