From 13a21486cf9a6688c01d497844012913f2c89c2d Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Sat, 18 Nov 2017 13:03:13 +0900 Subject: [PATCH] Fix verbose option --- file_checker.go | 10 ++++++---- main.go | 4 ++-- url_checker.go | 7 +++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/file_checker.go b/file_checker.go index 059e7a9..f86f68b 100644 --- a/file_checker.go +++ b/file_checker.go @@ -14,8 +14,8 @@ type fileChecker struct { urlChecker urlChecker } -func newFileChecker(timeout time.Duration, verbose bool) fileChecker { - return fileChecker{newURLChecker(timeout, verbose)} +func newFileChecker(timeout time.Duration) fileChecker { + return fileChecker{newURLChecker(timeout)} } func (c fileChecker) Check(f string) ([]urlResult, error) { @@ -50,11 +50,13 @@ type fileResult struct { err error } -func (r fileResult) String() string { +func (r fileResult) String(verbose bool) string { ss := make([]string, 0, len(r.urlResults)) for _, r := range r.urlResults { - ss = append(ss, "\t"+r.String()) + if r.err != nil || verbose { + ss = append(ss, "\t"+r.String()) + } } return strings.Join(append([]string{r.filename}, ss...), "\n") diff --git a/main.go b/main.go index 08f5d23..b583225 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,7 @@ func main() { args := getArgs() fs := args[""].([]string) rc := make(chan fileResult, len(fs)) - c := newFileChecker(5*time.Second, args["--verbose"].(bool)) + c := newFileChecker(5 * time.Second) for _, f := range fs { go func(f string) { @@ -49,7 +49,7 @@ func main() { ok = ok && r.Ok() - printToStderr(r.String()) + printToStderr(r.String(args["--verbose"].(bool))) } if !ok { diff --git a/url_checker.go b/url_checker.go index 168fed6..313946e 100644 --- a/url_checker.go +++ b/url_checker.go @@ -9,12 +9,11 @@ import ( ) type urlChecker struct { - client http.Client - verbose bool + client http.Client } -func newURLChecker(timeout time.Duration, verbose bool) urlChecker { - return urlChecker{http.Client{Timeout: timeout}, verbose} +func newURLChecker(timeout time.Duration) urlChecker { + return urlChecker{http.Client{Timeout: timeout}} } func (c urlChecker) Check(s string) error {