mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 04:32:30 +08:00
pkg/util/{filepath.go,shortid_generator.go}: Fix golint issues
See, $ gometalinter --vendor --deadline 10m --disable-all --enable=golint ./... filepath.go:12:5⚠️ error var WalkSkipDir should have name of the form ErrFoo (golint) shortid_generator.go:11:5⚠️ var validUidPattern should be validUIDPattern (golint) shortid_generator.go:19:6⚠️ func IsValidShortUid should be IsValidShortUID (golint) shortid_generator.go:24:6⚠️ func GenerateShortUid should be GenerateShortUID (golint)
This commit is contained in:
@ -20,7 +20,7 @@ func TestMiddlewareDashboardRedirect(t *testing.T) {
|
|||||||
fakeDash.Id = 1
|
fakeDash.Id = 1
|
||||||
fakeDash.FolderId = 1
|
fakeDash.FolderId = 1
|
||||||
fakeDash.HasAcl = false
|
fakeDash.HasAcl = false
|
||||||
fakeDash.Uid = util.GenerateShortUid()
|
fakeDash.Uid = util.GenerateShortUID()
|
||||||
|
|
||||||
bus.AddHandler("test", func(query *m.GetDashboardQuery) error {
|
bus.AddHandler("test", func(query *m.GetDashboardQuery) error {
|
||||||
query.Result = fakeDash
|
query.Result = fakeDash
|
||||||
|
@ -169,7 +169,7 @@ func (scanner *PluginScanner) walker(currentPath string, f os.FileInfo, err erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
if f.Name() == "node_modules" {
|
if f.Name() == "node_modules" {
|
||||||
return util.WalkSkipDir
|
return util.ErrWalkSkipDir
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
|
@ -80,7 +80,7 @@ func (dr *dashboardServiceImpl) buildSaveDashboardCommand(dto *SaveDashboardDTO,
|
|||||||
return nil, models.ErrDashboardFolderNameExists
|
return nil, models.ErrDashboardFolderNameExists
|
||||||
}
|
}
|
||||||
|
|
||||||
if !util.IsValidShortUid(dash.Uid) {
|
if !util.IsValidShortUID(dash.Uid) {
|
||||||
return nil, models.ErrDashboardInvalidUid
|
return nil, models.ErrDashboardInvalidUid
|
||||||
} else if len(dash.Uid) > 40 {
|
} else if len(dash.Uid) > 40 {
|
||||||
return nil, models.ErrDashboardUidToLong
|
return nil, models.ErrDashboardUidToLong
|
||||||
|
@ -27,7 +27,7 @@ func init() {
|
|||||||
bus.AddHandler("sql", HasEditPermissionInFolders)
|
bus.AddHandler("sql", HasEditPermissionInFolders)
|
||||||
}
|
}
|
||||||
|
|
||||||
var generateNewUid func() string = util.GenerateShortUid
|
var generateNewUid func() string = util.GenerateShortUID
|
||||||
|
|
||||||
func SaveDashboard(cmd *m.SaveDashboardCommand) error {
|
func SaveDashboard(cmd *m.SaveDashboardCommand) error {
|
||||||
return inTransaction(func(sess *DBSession) error {
|
return inTransaction(func(sess *DBSession) error {
|
||||||
|
@ -106,7 +106,7 @@ func TestDashboardDataAccess(t *testing.T) {
|
|||||||
if timesCalled <= 2 {
|
if timesCalled <= 2 {
|
||||||
return savedDash.Uid
|
return savedDash.Uid
|
||||||
}
|
}
|
||||||
return util.GenerateShortUid()
|
return util.GenerateShortUID()
|
||||||
}
|
}
|
||||||
cmd := m.SaveDashboardCommand{
|
cmd := m.SaveDashboardCommand{
|
||||||
OrgId: 1,
|
OrgId: 1,
|
||||||
@ -119,7 +119,7 @@ func TestDashboardDataAccess(t *testing.T) {
|
|||||||
err := SaveDashboard(&cmd)
|
err := SaveDashboard(&cmd)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
generateNewUid = util.GenerateShortUid
|
generateNewUid = util.GenerateShortUID
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Should be able to create dashboard", func() {
|
Convey("Should be able to create dashboard", func() {
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
//WalkSkipDir is the Error returned when we want to skip descending into a directory
|
//ErrWalkSkipDir is the Error returned when we want to skip descending into a directory
|
||||||
var WalkSkipDir = errors.New("skip this directory")
|
var ErrWalkSkipDir = errors.New("skip this directory")
|
||||||
|
|
||||||
//WalkFunc is a callback function called for each path as a directory is walked
|
//WalkFunc is a callback function called for each path as a directory is walked
|
||||||
//If resolvedPath != "", then we are following symbolic links.
|
//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)
|
err := walkFn(resolvedPath, info, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if info.IsDir() && err == WalkSkipDir {
|
if info.IsDir() && err == ErrWalkSkipDir {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -8,19 +8,19 @@ import (
|
|||||||
|
|
||||||
var allowedChars = shortid.DefaultABC
|
var allowedChars = shortid.DefaultABC
|
||||||
|
|
||||||
var validUidPattern = regexp.MustCompile(`^[a-zA-Z0-9\-\_]*$`).MatchString
|
var validUIDPattern = regexp.MustCompile(`^[a-zA-Z0-9\-\_]*$`).MatchString
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
gen, _ := shortid.New(1, allowedChars, 1)
|
gen, _ := shortid.New(1, allowedChars, 1)
|
||||||
shortid.SetDefault(gen)
|
shortid.SetDefault(gen)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValidShortUid checks if short unique identifier contains valid characters
|
// IsValidShortUID checks if short unique identifier contains valid characters
|
||||||
func IsValidShortUid(uid string) bool {
|
func IsValidShortUID(uid string) bool {
|
||||||
return validUidPattern(uid)
|
return validUIDPattern(uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateShortUid generates a short unique identifier.
|
// GenerateShortUID generates a short unique identifier.
|
||||||
func GenerateShortUid() string {
|
func GenerateShortUID() string {
|
||||||
return shortid.MustGenerate()
|
return shortid.MustGenerate()
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import "testing"
|
|||||||
|
|
||||||
func TestAllowedCharMatchesUidPattern(t *testing.T) {
|
func TestAllowedCharMatchesUidPattern(t *testing.T) {
|
||||||
for _, c := range allowedChars {
|
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")
|
t.Fatalf("charset for creating new shortids contains chars not present in uid pattern")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user