From b7628f2060c58ee9838f40bb26289881e47ef3b5 Mon Sep 17 00:00:00 2001 From: Mario Trangoni Date: Mon, 28 Jan 2019 22:37:44 +0100 Subject: [PATCH] pkg/util/{filepath.go,shortid_generator.go}: Fix golint issues See, $ gometalinter --vendor --deadline 10m --disable-all --enable=golint ./... filepath.go:12:5:warning: error var WalkSkipDir should have name of the form ErrFoo (golint) shortid_generator.go:11:5:warning: var validUidPattern should be validUIDPattern (golint) shortid_generator.go:19:6:warning: func IsValidShortUid should be IsValidShortUID (golint) shortid_generator.go:24:6:warning: func GenerateShortUid should be GenerateShortUID (golint) --- pkg/middleware/dashboard_redirect_test.go | 2 +- pkg/plugins/plugins.go | 2 +- pkg/services/dashboards/dashboard_service.go | 2 +- pkg/services/sqlstore/dashboard.go | 2 +- pkg/services/sqlstore/dashboard_test.go | 4 ++-- pkg/util/filepath.go | 6 +++--- pkg/util/shortid_generator.go | 12 ++++++------ pkg/util/shortid_generator_test.go | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/middleware/dashboard_redirect_test.go b/pkg/middleware/dashboard_redirect_test.go index 1e4d8293cae..ebef4c92730 100644 --- a/pkg/middleware/dashboard_redirect_test.go +++ b/pkg/middleware/dashboard_redirect_test.go @@ -20,7 +20,7 @@ func TestMiddlewareDashboardRedirect(t *testing.T) { fakeDash.Id = 1 fakeDash.FolderId = 1 fakeDash.HasAcl = false - fakeDash.Uid = util.GenerateShortUid() + fakeDash.Uid = util.GenerateShortUID() bus.AddHandler("test", func(query *m.GetDashboardQuery) error { query.Result = fakeDash diff --git a/pkg/plugins/plugins.go b/pkg/plugins/plugins.go index 4f15441bb2f..b10e4640f4b 100644 --- a/pkg/plugins/plugins.go +++ b/pkg/plugins/plugins.go @@ -169,7 +169,7 @@ func (scanner *PluginScanner) walker(currentPath string, f os.FileInfo, err erro } if f.Name() == "node_modules" { - return util.WalkSkipDir + return util.ErrWalkSkipDir } if f.IsDir() { diff --git a/pkg/services/dashboards/dashboard_service.go b/pkg/services/dashboards/dashboard_service.go index 33f418cbee3..f8df6763994 100644 --- a/pkg/services/dashboards/dashboard_service.go +++ b/pkg/services/dashboards/dashboard_service.go @@ -80,7 +80,7 @@ func (dr *dashboardServiceImpl) buildSaveDashboardCommand(dto *SaveDashboardDTO, return nil, models.ErrDashboardFolderNameExists } - if !util.IsValidShortUid(dash.Uid) { + if !util.IsValidShortUID(dash.Uid) { return nil, models.ErrDashboardInvalidUid } else if len(dash.Uid) > 40 { return nil, models.ErrDashboardUidToLong diff --git a/pkg/services/sqlstore/dashboard.go b/pkg/services/sqlstore/dashboard.go index bad46c10af4..7ebdbfa65e7 100644 --- a/pkg/services/sqlstore/dashboard.go +++ b/pkg/services/sqlstore/dashboard.go @@ -27,7 +27,7 @@ func init() { bus.AddHandler("sql", HasEditPermissionInFolders) } -var generateNewUid func() string = util.GenerateShortUid +var generateNewUid func() string = util.GenerateShortUID func SaveDashboard(cmd *m.SaveDashboardCommand) error { return inTransaction(func(sess *DBSession) error { diff --git a/pkg/services/sqlstore/dashboard_test.go b/pkg/services/sqlstore/dashboard_test.go index 8ff78c4a0ff..1a82d314de0 100644 --- a/pkg/services/sqlstore/dashboard_test.go +++ b/pkg/services/sqlstore/dashboard_test.go @@ -106,7 +106,7 @@ func TestDashboardDataAccess(t *testing.T) { if timesCalled <= 2 { return savedDash.Uid } - return util.GenerateShortUid() + return util.GenerateShortUID() } cmd := m.SaveDashboardCommand{ OrgId: 1, @@ -119,7 +119,7 @@ func TestDashboardDataAccess(t *testing.T) { err := SaveDashboard(&cmd) So(err, ShouldBeNil) - generateNewUid = util.GenerateShortUid + generateNewUid = util.GenerateShortUID }) Convey("Should be able to create dashboard", func() { diff --git a/pkg/util/filepath.go b/pkg/util/filepath.go index d304236fcb1..368c6fa40d5 100644 --- a/pkg/util/filepath.go +++ b/pkg/util/filepath.go @@ -8,8 +8,8 @@ import ( "path/filepath" ) -//WalkSkipDir is the Error returned when we want to skip descending into a directory -var WalkSkipDir = errors.New("skip this directory") +//ErrWalkSkipDir is the Error returned when we want to skip descending into a directory +var ErrWalkSkipDir = errors.New("skip this directory") //WalkFunc is a callback function called for each path as a directory is walked //If resolvedPath != "", then we are following symbolic links. @@ -50,7 +50,7 @@ func walk(path string, info os.FileInfo, resolvedPath string, symlinkPathsFollow } err := walkFn(resolvedPath, info, nil) if err != nil { - if info.IsDir() && err == WalkSkipDir { + if info.IsDir() && err == ErrWalkSkipDir { err = nil } return err diff --git a/pkg/util/shortid_generator.go b/pkg/util/shortid_generator.go index f900cb8275e..c035e088944 100644 --- a/pkg/util/shortid_generator.go +++ b/pkg/util/shortid_generator.go @@ -8,19 +8,19 @@ import ( var allowedChars = shortid.DefaultABC -var validUidPattern = regexp.MustCompile(`^[a-zA-Z0-9\-\_]*$`).MatchString +var validUIDPattern = regexp.MustCompile(`^[a-zA-Z0-9\-\_]*$`).MatchString func init() { gen, _ := shortid.New(1, allowedChars, 1) shortid.SetDefault(gen) } -// IsValidShortUid checks if short unique identifier contains valid characters -func IsValidShortUid(uid string) bool { - return validUidPattern(uid) +// IsValidShortUID checks if short unique identifier contains valid characters +func IsValidShortUID(uid string) bool { + return validUIDPattern(uid) } -// GenerateShortUid generates a short unique identifier. -func GenerateShortUid() string { +// GenerateShortUID generates a short unique identifier. +func GenerateShortUID() string { return shortid.MustGenerate() } diff --git a/pkg/util/shortid_generator_test.go b/pkg/util/shortid_generator_test.go index 359e054a0ca..94055f0bcfd 100644 --- a/pkg/util/shortid_generator_test.go +++ b/pkg/util/shortid_generator_test.go @@ -4,7 +4,7 @@ import "testing" func TestAllowedCharMatchesUidPattern(t *testing.T) { for _, c := range allowedChars { - if !IsValidShortUid(string(c)) { + if !IsValidShortUID(string(c)) { t.Fatalf("charset for creating new shortids contains chars not present in uid pattern") } }