Commit 4829ea0e by Marcus Efraimsson

util: remove retry logic in shortid_generator

Use shortid.MustGenerate() instead of shortid.Generate(). Instead
of returning errors it will panic.
parent 9fb7b887
...@@ -65,7 +65,7 @@ type Dashboard struct { ...@@ -65,7 +65,7 @@ type Dashboard struct {
// NewDashboard creates a new dashboard // NewDashboard creates a new dashboard
func NewDashboard(title string) *Dashboard { func NewDashboard(title string) *Dashboard {
dash := &Dashboard{} dash := &Dashboard{}
dash.Uid, _ = util.GenerateShortUid() dash.Uid = util.GenerateShortUid()
dash.Data = simplejson.New() dash.Data = simplejson.New()
dash.Data.Set("title", title) dash.Data.Set("title", title)
dash.Title = title dash.Title = title
...@@ -115,7 +115,7 @@ func NewDashboardFromJson(data *simplejson.Json) *Dashboard { ...@@ -115,7 +115,7 @@ func NewDashboardFromJson(data *simplejson.Json) *Dashboard {
if uid, err := dash.Data.Get("uid").String(); err == nil { if uid, err := dash.Data.Get("uid").String(); err == nil {
dash.Uid = uid dash.Uid = uid
} else { } else {
dash.Uid, _ = util.GenerateShortUid() dash.Uid = util.GenerateShortUid()
} }
return dash return dash
......
...@@ -7,18 +7,9 @@ import ( ...@@ -7,18 +7,9 @@ import (
func init() { func init() {
gen, _ := shortid.New(1, shortid.DefaultABC, 1) gen, _ := shortid.New(1, shortid.DefaultABC, 1)
shortid.SetDefault(gen) shortid.SetDefault(gen)
} }
// GenerateShortUid generates a short unique identifier. // GenerateShortUid generates a short unique identifier.
func GenerateShortUid() (uid string, err error) { func GenerateShortUid() string {
if uid, err = shortid.Generate(); err != nil { return shortid.MustGenerate()
if uid, err = shortid.Generate(); err != nil {
if uid, err = shortid.Generate(); err != nil {
return "", err
}
}
}
return uid, nil
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment