From 4e7104ab81d8961e5ab7ee7dcc3603f84573409c Mon Sep 17 00:00:00 2001 From: Annika Hannig Date: Mon, 15 Nov 2021 21:43:22 +0100 Subject: [PATCH] fixed more linter errors --- pkg/api/bgp_communities_test.go | 4 ++-- pkg/http/api.go | 2 +- pkg/http/api_endpoints_search.go | 2 -- pkg/http/api_validators.go | 30 ++---------------------------- pkg/http/server.go | 2 ++ pkg/http/theme_test.go | 6 +++--- pkg/http/web.go | 4 ++-- 7 files changed, 12 insertions(+), 38 deletions(-) diff --git a/pkg/api/bgp_communities_test.go b/pkg/api/bgp_communities_test.go index 2e95aec..235d99f 100644 --- a/pkg/api/bgp_communities_test.go +++ b/pkg/api/bgp_communities_test.go @@ -17,12 +17,12 @@ func TestCommunityLookup(t *testing.T) { } // Okay now try some fails - label, err = c.Lookup("65535") + _, err = c.Lookup("65535") if err == nil { t.Error("Expected error!") } - label, err = c.Lookup("65535:23:42") + _, err = c.Lookup("65535:23:42") if err == nil { t.Error("Expected not found error!") } diff --git a/pkg/http/api.go b/pkg/http/api.go index c2ece13..adc128a 100644 --- a/pkg/http/api.go +++ b/pkg/http/api.go @@ -109,7 +109,7 @@ func (s *Server) apiRegisterEndpoints( endpoint(s.apiRoutesListNotExported)) // Querying - if s.cfg.Server.EnablePrefixLookup == true { + if s.cfg.Server.EnablePrefixLookup { router.GET("/api/v1/lookup/prefix", endpoint(s.apiLookupPrefixGlobal)) router.GET("/api/v1/lookup/neighbors", diff --git a/pkg/http/api_endpoints_search.go b/pkg/http/api_endpoints_search.go index d0c4823..89c9fbe 100644 --- a/pkg/http/api_endpoints_search.go +++ b/pkg/http/api_endpoints_search.go @@ -71,10 +71,8 @@ func (s *Server) apiLookupPrefixGlobal( switch r.State { case "filtered": filtered = append(filtered, r) - break case "imported": imported = append(imported, r) - break } filtersAvailable.UpdateFromLookupRoute(r) diff --git a/pkg/http/api_validators.go b/pkg/http/api_validators.go index 7b443b1..5c4a265 100644 --- a/pkg/http/api_validators.go +++ b/pkg/http/api_validators.go @@ -2,7 +2,6 @@ package http import ( "fmt" - "strconv" "net/http" ) @@ -10,7 +9,7 @@ import ( // Helper: Validate source Id func validateSourceID(id string) (string, error) { if len(id) > 42 { - return "unknown", fmt.Errorf("Source ID too long with length: %d", len(id)) + return "unknown", fmt.Errorf("source ID too long with length: %d", len(id)) } return id, nil } @@ -39,32 +38,7 @@ func validateQueryString(req *http.Request, key string) (string, error) { func validatePrefixQuery(value string) (string, error) { // We should at least provide 2 chars if len(value) < 2 { - return "", fmt.Errorf("Query too short") + return "", fmt.Errorf("query too short") } return value, nil } - -// Get pagination parameters: limit and offset -// Refer to defaults if none are given. -func validatePaginationParams(req *http.Request, limit, offset int) (int, int, error) { - query := req.URL.Query() - queryLimit, ok := query["limit"] - if ok { - limit, _ = strconv.Atoi(queryLimit[0]) - } - - queryOffset, ok := query["offset"] - if ok { - offset, _ = strconv.Atoi(queryOffset[0]) - } - - // Cap limit to [1, 1000] - if limit < 1 { - limit = 1 - } - if limit > 500 { - limit = 500 - } - - return limit, offset, nil -} diff --git a/pkg/http/server.go b/pkg/http/server.go index bfee026..baff2a4 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -1,3 +1,5 @@ +// Package http provides the server and API implementation +// for the webclient. The webclient's static files are also served. package http import ( diff --git a/pkg/http/theme_test.go b/pkg/http/theme_test.go index c8d1a2e..38ed27d 100644 --- a/pkg/http/theme_test.go +++ b/pkg/http/theme_test.go @@ -104,17 +104,17 @@ func TestThemeIncludes(t *testing.T) { if !strings.HasPrefix(scriptsHTML, "