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 {
// NewDashboard creates a new dashboard
func NewDashboard(title string) *Dashboard {
dash := &Dashboard{}
dash.Uid, _ = util.GenerateShortUid()
dash.Uid = util.GenerateShortUid()
dash.Data = simplejson.New()
dash.Data.Set("title", title)
dash.Title = title
......@@ -115,7 +115,7 @@ func NewDashboardFromJson(data *simplejson.Json) *Dashboard {
if uid, err := dash.Data.Get("uid").String(); err == nil {
dash.Uid = uid
} else {
dash.Uid, _ = util.GenerateShortUid()
dash.Uid = util.GenerateShortUid()
}
return dash
......
......@@ -7,18 +7,9 @@ import (
func init() {
gen, _ := shortid.New(1, shortid.DefaultABC, 1)
shortid.SetDefault(gen)
}
// GenerateShortUid generates a short unique identifier.
func GenerateShortUid() (uid string, err error) {
if uid, err = shortid.Generate(); err != nil {
if uid, err = shortid.Generate(); err != nil {
if uid, err = shortid.Generate(); err != nil {
return "", err
}
}
}
return uid, nil
func GenerateShortUid() string {
return shortid.MustGenerate()
}
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