From 6d2e6363dd92838e698f48e6fd5aaf17e9b73e59 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Mon, 21 Sep 2015 15:50:21 +0800 Subject: [PATCH] use strings.TrimSpace to trim string --- hosts.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/hosts.go b/hosts.go index e16bdf0..994ea59 100644 --- a/hosts.go +++ b/hosts.go @@ -60,7 +60,7 @@ func ReadHosts(fn string) (Hosts, error) { } sline := string(bline) - sline = strings.Trim(sline, " ") + sline = strings.TrimSpace(sline) /* empty line */ if sline == "" { @@ -72,12 +72,9 @@ func ReadHosts(fn string) (Hosts, error) { continue } - /* replace tab to space */ - sline = strings.Replace(sline, "\t", " ", -1) + lns := strings.Fields(sline) - lns := strings.Split(sline, " ") - - if len(lns) < 1 { + if len(lns) < 2 { return nil, errors.New(fmt.Sprintf("invalid hosts line: %s", sline)) } @@ -94,7 +91,7 @@ func ReadHosts(fn string) (Hosts, error) { for _, dn := range lns[1:] { - dd := dns.Fqdn(strings.Trim(dn, " ")) + dd := dns.Fqdn(strings.TrimSpace(dn)) /* ignore space */ if dd == "." {