From 504e089367cd53afb84133e342168d09db8380c5 Mon Sep 17 00:00:00 2001 From: nitram509 Date: Fri, 29 Mar 2024 11:48:11 +0100 Subject: [PATCH] trim spaces --- port_settings.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/port_settings.go b/port_settings.go index 5011398..37d3115 100644 --- a/port_settings.go +++ b/port_settings.go @@ -5,6 +5,7 @@ import ( "github.com/PuerkitoBio/goquery" "io" "strconv" + "strings" ) type PortCommand struct { @@ -61,7 +62,8 @@ func prettyPrintPortSettings(format OutputFormat, settings []Port) { func findPortSettingsInHtml(model NetgearModel, reader io.Reader) ([]Port, error) { if isModel30x(model) { return findPortSettingsInGs30xEPxHtml(reader) - } else if isModel316(model) { + } + if isModel316(model) { return findPortSettingsInGs316EPxHtml(reader) } panic("model not supported") @@ -105,23 +107,23 @@ func findPortSettingsInGs316EPxHtml(reader io.Reader) (ports []Port, err error) }) s.Find("span.port-number").Each(func(i int, selection *goquery.Selection) { - var id64, _ = strconv.ParseInt(selection.Text(), 10, 8) + var id64, _ = strconv.ParseInt(strings.TrimSpace(selection.Text()), 10, 8) ports[i].Index = int8(id64) }) s.Find("span.port-name span.name").Each(func(i int, selection *goquery.Selection) { - ports[i].Name = selection.Text() + ports[i].Name = strings.TrimSpace(selection.Text()) }) s.Find("p.speed-text").Each(func(i int, selection *goquery.Selection) { - ports[i].Speed = selection.Text() + ports[i].Speed = strings.TrimSpace(selection.Text()) }) s.Find("p.ingress-text").Each(func(i int, selection *goquery.Selection) { - ports[i].IngressRateLimit = selection.Text() + ports[i].IngressRateLimit = strings.TrimSpace(selection.Text()) }) s.Find("p.egress-text").Each(func(i int, selection *goquery.Selection) { - ports[i].EgressRateLimit = selection.Text() + ports[i].EgressRateLimit = strings.TrimSpace(selection.Text()) }) s.Find("p.flow-text").Each(func(i int, selection *goquery.Selection) { - ports[i].FlowControl = selection.Text() + ports[i].FlowControl = strings.TrimSpace(selection.Text()) }) })