fixed more linter errors

This commit is contained in:
Annika Hannig 2021-11-15 21:43:22 +01:00
parent c5ea17695f
commit 4e7104ab81
7 changed files with 12 additions and 38 deletions

View File

@ -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!")
}

View File

@ -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",

View File

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

View File

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

View File

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

View File

@ -104,17 +104,17 @@ func TestThemeIncludes(t *testing.T) {
if !strings.HasPrefix(scriptsHTML, "<script") {
t.Error("Script include should start with <script")
}
if strings.Index(scriptsHTML, "script.js") == -1 {
if !strings.Contains(scriptsHTML, "script.js") {
t.Error("Scripts include should contain script.js")
}
if !strings.HasPrefix(stylesHTML, "<link") {
t.Error("Stylesheet include should start with <link")
}
if strings.Index(stylesHTML, "extra.css") == -1 {
if !strings.Contains(stylesHTML, "extra.css") {
t.Error("Stylesheet include should contain extra.css")
}
if strings.Index(stylesHTML, "script.js") != -1 {
if !strings.Contains(stylesHTML, "script.js") {
t.Error("Stylesheet include should not contain script.js")
}

View File

@ -16,7 +16,7 @@ import (
// Prepare client HTML:
// Set paths and add version to assets.
func (s*Server)webPrepareClientHTML(html string) string {
func (s *Server) webPrepareClientHTML(html string) string {
status, _ := CollectAppStatus(s.routesStore, s.neighborsStore)
// Replace paths and tags
@ -85,7 +85,7 @@ func (s *Server) webRegisterAssets(router *httprouter.Router) error {
// ...install a catch all for /alice for graceful backwards compatibility
router.GET("/alice/*path",
func(res http.ResponseWriter, req *http.Request, _ httprouter.Params) {
http.Redirect(res, req, "/", 301)
http.Redirect(res, req, "/", http.StatusMovedPermanently)
})
return nil