mirror of
https://github.com/documize/community.git
synced 2025-07-19 13:19:43 +02:00
refactored unique ID generator package
This commit is contained in:
parent
cf58f8164d
commit
fe05cf7bb5
16 changed files with 69 additions and 64 deletions
|
@ -22,9 +22,9 @@ import (
|
|||
|
||||
"github.com/documize/community/core/api/entity"
|
||||
"github.com/documize/community/core/api/request"
|
||||
"github.com/documize/community/core/api/util"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/secrets"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
"github.com/gorilla/mux"
|
||||
_ "github.com/mytrile/mime-ext" // this adds a large number of mime extensions
|
||||
uuid "github.com/nu7hatch/gouuid"
|
||||
|
@ -192,7 +192,7 @@ func AddAttachments(w http.ResponseWriter, r *http.Request) {
|
|||
job = newUUID.String()
|
||||
|
||||
var a entity.Attachment
|
||||
refID := util.UniqueID()
|
||||
refID := uniqueid.Generate()
|
||||
a.RefID = refID
|
||||
a.DocumentID = documentID
|
||||
a.Job = job
|
||||
|
|
|
@ -25,9 +25,9 @@ import (
|
|||
"github.com/documize/community/core/api/entity"
|
||||
"github.com/documize/community/core/api/request"
|
||||
"github.com/documize/community/core/api/store"
|
||||
"github.com/documize/community/core/api/util"
|
||||
api "github.com/documize/community/core/convapi"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
"github.com/gorilla/mux"
|
||||
uuid "github.com/nu7hatch/gouuid"
|
||||
)
|
||||
|
@ -154,7 +154,7 @@ func processDocument(p request.Persister, filename, job, folderID string, fileRe
|
|||
document.OrgID = p.Context.OrgID
|
||||
document.LabelID = folderID
|
||||
document.UserID = p.Context.UserID
|
||||
documentID := util.UniqueID()
|
||||
documentID := uniqueid.Generate()
|
||||
document.RefID = documentID
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
|
@ -181,7 +181,7 @@ func processDocument(p request.Persister, filename, job, folderID string, fileRe
|
|||
page.Title = v.Title
|
||||
page.Body = string(v.Body)
|
||||
page.Sequence = float64(k+1) * 1024.0 // need to start above 0 to allow insertion before the first item
|
||||
pageID := util.UniqueID()
|
||||
pageID := uniqueid.Generate()
|
||||
page.RefID = pageID
|
||||
page.ContentType = "wysiwyg"
|
||||
page.PageType = "section"
|
||||
|
@ -212,7 +212,7 @@ func processDocument(p request.Persister, filename, job, folderID string, fileRe
|
|||
a.FileID = e.ID
|
||||
a.Filename = strings.Replace(e.Name, "embeddings/", "", 1)
|
||||
a.Data = e.Data
|
||||
refID := util.UniqueID()
|
||||
refID := uniqueid.Generate()
|
||||
a.RefID = refID
|
||||
|
||||
err = p.AddAttachment(a)
|
||||
|
|
|
@ -33,6 +33,7 @@ import (
|
|||
"github.com/documize/community/core/secrets"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/core/stringutil"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
)
|
||||
|
||||
// AuthenticateKeycloak checks Keycloak authentication credentials.
|
||||
|
@ -291,7 +292,7 @@ func addUser(p request.Persister, u *entity.User, addSpace bool) (err error) {
|
|||
}
|
||||
|
||||
if addUser {
|
||||
userID = util.UniqueID()
|
||||
userID = uniqueid.Generate()
|
||||
u.RefID = userID
|
||||
err = p.AddUser(*u)
|
||||
|
||||
|
@ -317,7 +318,7 @@ func addUser(p request.Persister, u *entity.User, addSpace bool) (err error) {
|
|||
a.OrgID = p.Context.OrgID
|
||||
a.Editor = addSpace
|
||||
a.Admin = false
|
||||
accountID := util.UniqueID()
|
||||
accountID := uniqueid.Generate()
|
||||
a.RefID = accountID
|
||||
a.Active = true
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/documize/community/core/secrets"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/core/stringutil"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
)
|
||||
|
||||
// AddFolder creates a new folder.
|
||||
|
@ -72,7 +73,7 @@ func AddFolder(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
p.Context.Transaction = tx
|
||||
|
||||
id := util.UniqueID()
|
||||
id := uniqueid.Generate()
|
||||
folder.RefID = id
|
||||
folder.OrgID = p.Context.OrgID
|
||||
|
||||
|
@ -114,7 +115,7 @@ func addFolder(p request.Persister, label *entity.Label) (err error) {
|
|||
role.UserID = p.Context.UserID
|
||||
role.CanEdit = true
|
||||
role.CanView = true
|
||||
refID := util.UniqueID()
|
||||
refID := uniqueid.Generate()
|
||||
role.RefID = refID
|
||||
|
||||
err = p.AddLabelRole(role)
|
||||
|
@ -511,7 +512,7 @@ func SetFolderPermissions(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// Only persist if there is a role!
|
||||
if role.CanView || role.CanEdit {
|
||||
roleID := util.UniqueID()
|
||||
roleID := uniqueid.Generate()
|
||||
role.RefID = roleID
|
||||
err = p.AddLabelRole(role)
|
||||
roleCount++
|
||||
|
@ -545,7 +546,7 @@ func SetFolderPermissions(w http.ResponseWriter, r *http.Request) {
|
|||
role.UserID = p.Context.UserID
|
||||
role.CanEdit = true
|
||||
role.CanView = true
|
||||
roleID := util.UniqueID()
|
||||
roleID := uniqueid.Generate()
|
||||
role.RefID = roleID
|
||||
err = p.AddLabelRole(role)
|
||||
log.IfErr(err)
|
||||
|
@ -800,7 +801,7 @@ func InviteToFolder(w http.ResponseWriter, r *http.Request) {
|
|||
a.Admin = false
|
||||
a.Editor = false
|
||||
a.Active = true
|
||||
accountID := util.UniqueID()
|
||||
accountID := uniqueid.Generate()
|
||||
a.RefID = accountID
|
||||
|
||||
err = p.AddAccount(a)
|
||||
|
@ -822,7 +823,7 @@ func InviteToFolder(w http.ResponseWriter, r *http.Request) {
|
|||
role.UserID = user.RefID
|
||||
role.CanEdit = false
|
||||
role.CanView = true
|
||||
roleID := util.UniqueID()
|
||||
roleID := uniqueid.Generate()
|
||||
role.RefID = roleID
|
||||
|
||||
err = p.AddLabelRole(role)
|
||||
|
@ -887,7 +888,7 @@ func inviteNewUserToSharedFolder(p request.Persister, email string, invitedBy en
|
|||
user.Salt = secrets.GenerateSalt()
|
||||
requestedPassword := secrets.GenerateRandomPassword()
|
||||
user.Password = secrets.GeneratePassword(requestedPassword, user.Salt)
|
||||
userID := util.UniqueID()
|
||||
userID := uniqueid.Generate()
|
||||
user.RefID = userID
|
||||
|
||||
err = p.AddUser(user)
|
||||
|
@ -903,7 +904,7 @@ func inviteNewUserToSharedFolder(p request.Persister, email string, invitedBy en
|
|||
a.Admin = false
|
||||
a.Editor = false
|
||||
a.Active = true
|
||||
accountID := util.UniqueID()
|
||||
accountID := uniqueid.Generate()
|
||||
a.RefID = accountID
|
||||
|
||||
err = p.AddAccount(a)
|
||||
|
@ -918,7 +919,7 @@ func inviteNewUserToSharedFolder(p request.Persister, email string, invitedBy en
|
|||
role.UserID = userID
|
||||
role.CanEdit = false
|
||||
role.CanView = true
|
||||
roleID := util.UniqueID()
|
||||
roleID := uniqueid.Generate()
|
||||
role.RefID = roleID
|
||||
|
||||
err = p.AddLabelRole(role)
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/documize/community/core/api/request"
|
||||
"github.com/documize/community/core/api/util"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
)
|
||||
|
||||
// GetLinkCandidates returns references to documents/sections/attachments.
|
||||
|
@ -70,7 +71,7 @@ func GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
for _, p := range pages {
|
||||
if p.RefID != pageID {
|
||||
c := entity.LinkCandidate{
|
||||
RefID: util.UniqueID(),
|
||||
RefID: uniqueid.Generate(),
|
||||
FolderID: folderID,
|
||||
DocumentID: documentID,
|
||||
TargetID: p.RefID,
|
||||
|
@ -98,7 +99,7 @@ func GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
for _, f := range files {
|
||||
c := entity.LinkCandidate{
|
||||
RefID: util.UniqueID(),
|
||||
RefID: uniqueid.Generate(),
|
||||
FolderID: folderID,
|
||||
DocumentID: documentID,
|
||||
TargetID: f.RefID,
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/section/provider"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
htmldiff "github.com/documize/html-diff"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
@ -79,7 +80,7 @@ func AddDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
pageID := util.UniqueID()
|
||||
pageID := uniqueid.Generate()
|
||||
model.Page.RefID = pageID
|
||||
model.Meta.PageID = pageID
|
||||
model.Meta.OrgID = p.Context.OrgID // required for Render call below
|
||||
|
@ -530,7 +531,7 @@ func UpdateDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
var skipRevision bool
|
||||
skipRevision, err = strconv.ParseBool(r.URL.Query().Get("r"))
|
||||
|
||||
refID := util.UniqueID()
|
||||
refID := uniqueid.Generate()
|
||||
err = p.UpdatePage(model.Page, refID, p.Context.UserID, skipRevision)
|
||||
if err != nil {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
|
@ -1001,7 +1002,7 @@ func RollbackDocumentPage(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// roll back page
|
||||
page.Body = revision.Body
|
||||
refID := util.UniqueID()
|
||||
refID := uniqueid.Generate()
|
||||
|
||||
err = p.UpdatePage(page, refID, p.Context.UserID, false)
|
||||
if err != nil {
|
||||
|
@ -1101,7 +1102,7 @@ func CopyPage(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
newPageID := util.UniqueID()
|
||||
newPageID := uniqueid.Generate()
|
||||
page.RefID = newPageID
|
||||
page.Level = 1
|
||||
page.Sequence = 0
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"github.com/documize/community/core/api/request"
|
||||
"github.com/documize/community/core/api/util"
|
||||
"github.com/documize/community/core/log"
|
||||
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
|
@ -62,7 +62,7 @@ func AddPin(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
pin.RefID = util.UniqueID()
|
||||
pin.RefID = uniqueid.Generate()
|
||||
pin.OrgID = p.Context.OrgID
|
||||
pin.UserID = p.Context.UserID
|
||||
pin.Pin = strings.TrimSpace(pin.Pin)
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/section/provider"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
|
@ -153,7 +154,7 @@ func RefreshSections(w http.ResponseWriter, r *http.Request) {
|
|||
page.Body = body
|
||||
pages = append(pages, page)
|
||||
|
||||
refID := util.UniqueID()
|
||||
refID := uniqueid.Generate()
|
||||
err = p.UpdatePage(page, refID, p.Context.UserID, false)
|
||||
|
||||
if err != nil {
|
||||
|
@ -218,7 +219,7 @@ func AddBlock(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
b.RefID = util.UniqueID()
|
||||
b.RefID = uniqueid.Generate()
|
||||
|
||||
tx, err := request.Db.Beginx()
|
||||
if err != nil {
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/documize/community/core/secrets"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/core/stringutil"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
"github.com/gorilla/mux"
|
||||
uuid "github.com/nu7hatch/gouuid"
|
||||
)
|
||||
|
@ -88,7 +89,7 @@ func SaveAsTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
docID := util.UniqueID()
|
||||
docID := uniqueid.Generate()
|
||||
doc.Template = true
|
||||
doc.Title = model.Name
|
||||
doc.Excerpt = model.Excerpt
|
||||
|
@ -116,7 +117,7 @@ func SaveAsTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
pageID := util.UniqueID()
|
||||
pageID := uniqueid.Generate()
|
||||
page.RefID = pageID
|
||||
|
||||
meta.PageID = pageID
|
||||
|
@ -134,7 +135,7 @@ func SaveAsTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
attachments, _ := p.GetAttachments(model.DocumentID)
|
||||
for i, a := range attachments {
|
||||
a.DocumentID = docID
|
||||
a.RefID = util.UniqueID()
|
||||
a.RefID = uniqueid.Generate()
|
||||
a.ID = 0
|
||||
attachments[i] = a
|
||||
}
|
||||
|
@ -347,7 +348,7 @@ func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
d.Slug = stringutil.MakeSlug(d.Title)
|
||||
d.Tags = ""
|
||||
d.LabelID = folderID
|
||||
documentID := util.UniqueID()
|
||||
documentID := uniqueid.Generate()
|
||||
d.RefID = documentID
|
||||
|
||||
var pages = []entity.Page{}
|
||||
|
@ -382,7 +383,7 @@ func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
p.Context.Transaction = tx
|
||||
|
||||
// Prepare new document
|
||||
documentID = util.UniqueID()
|
||||
documentID = uniqueid.Generate()
|
||||
d.RefID = documentID
|
||||
d.Template = false
|
||||
d.LabelID = folderID
|
||||
|
@ -405,7 +406,7 @@ func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
page.DocumentID = documentID
|
||||
pageID := util.UniqueID()
|
||||
pageID := uniqueid.Generate()
|
||||
page.RefID = pageID
|
||||
|
||||
// meta := entity.PageMeta{}
|
||||
|
@ -440,7 +441,7 @@ func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
|
|||
a.Job = newUUID.String()
|
||||
random := secrets.GenerateSalt()
|
||||
a.FileID = random[0:9]
|
||||
attachmentID := util.UniqueID()
|
||||
attachmentID := uniqueid.Generate()
|
||||
a.RefID = attachmentID
|
||||
|
||||
err = p.AddAttachment(a)
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"github.com/documize/community/core/secrets"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/core/stringutil"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
|
@ -123,7 +124,7 @@ func AddUser(w http.ResponseWriter, r *http.Request) {
|
|||
p.Context.Transaction = tx
|
||||
|
||||
if addUser {
|
||||
userID = util.UniqueID()
|
||||
userID = uniqueid.Generate()
|
||||
userModel.RefID = userID
|
||||
err = p.AddUser(userModel)
|
||||
|
||||
|
@ -149,7 +150,7 @@ func AddUser(w http.ResponseWriter, r *http.Request) {
|
|||
// set up user account for the org
|
||||
if addAccount {
|
||||
var a entity.Account
|
||||
a.RefID = util.UniqueID()
|
||||
a.RefID = uniqueid.Generate()
|
||||
a.UserID = userID
|
||||
a.OrgID = p.Context.OrgID
|
||||
a.Editor = true
|
||||
|
|
|
@ -16,9 +16,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/documize/community/core/api/entity"
|
||||
"github.com/documize/community/core/api/util"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/streamutil"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
)
|
||||
|
||||
// AddContentLink inserts wiki-link into the store.
|
||||
|
@ -74,7 +74,7 @@ func (p *Persister) SearchLinkCandidates(keywords string) (docs []entity.LinkCan
|
|||
|
||||
for _, r := range temp {
|
||||
c := entity.LinkCandidate{
|
||||
RefID: util.UniqueID(),
|
||||
RefID: uniqueid.Generate(),
|
||||
FolderID: r.FolderID,
|
||||
DocumentID: r.DocumentID,
|
||||
TargetID: r.DocumentID,
|
||||
|
@ -113,7 +113,7 @@ func (p *Persister) SearchLinkCandidates(keywords string) (docs []entity.LinkCan
|
|||
|
||||
for _, r := range temp {
|
||||
c := entity.LinkCandidate{
|
||||
RefID: util.UniqueID(),
|
||||
RefID: uniqueid.Generate(),
|
||||
FolderID: r.FolderID,
|
||||
DocumentID: r.DocumentID,
|
||||
TargetID: r.TargetID,
|
||||
|
@ -152,7 +152,7 @@ func (p *Persister) SearchLinkCandidates(keywords string) (docs []entity.LinkCan
|
|||
|
||||
for _, r := range temp {
|
||||
c := entity.LinkCandidate{
|
||||
RefID: util.UniqueID(),
|
||||
RefID: uniqueid.Generate(),
|
||||
FolderID: r.FolderID,
|
||||
DocumentID: r.DocumentID,
|
||||
TargetID: r.TargetID,
|
||||
|
|
|
@ -15,7 +15,7 @@ package request
|
|||
|
||||
import (
|
||||
"github.com/documize/community/core/api/entity"
|
||||
"github.com/documize/community/core/api/util"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
)
|
||||
|
||||
// SetupPersister prepares context for database activity.
|
||||
|
@ -26,8 +26,8 @@ func SetupPersister() (*Persister, error) {
|
|||
Guest: false, // bool
|
||||
Administrator: true, // bool
|
||||
Editor: true, // bool
|
||||
UserID: util.UniqueID(), // string
|
||||
OrgID: util.UniqueID(), // string
|
||||
UserID: uniqueid.Generate(), // string
|
||||
OrgID: uniqueid.Generate(), // string
|
||||
//OrgURL: "http://wwww.test.org", // string
|
||||
//OrgName: "TestOrgName", // string
|
||||
AllowAnonymousAccess: false, // bool
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
var lsp LocalStorageProvider
|
||||
|
||||
func TestUpload(t *testing.T) {
|
||||
jb := "job" + util.UniqueID()
|
||||
jb := "job" + uniqueid.Generate()
|
||||
fn := "file.txt"
|
||||
cont := "content\n"
|
||||
err := lsp.Upload(jb, fn, []byte(cont))
|
||||
|
@ -54,7 +54,7 @@ func TestConvert(t *testing.T) {
|
|||
}
|
||||
defer log.IfErr(plugins.Lib.KillSubProcs())
|
||||
|
||||
jb := "job" + util.UniqueID()
|
||||
jb := "job" + uniqueid.Generate()
|
||||
|
||||
_, _, err =
|
||||
lsp.Convert(api.ConversionJobRequest{
|
||||
|
|
|
@ -18,10 +18,10 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/api/util"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/secrets"
|
||||
"github.com/documize/community/core/stringutil"
|
||||
"github.com/documize/community/core/uniqueid"
|
||||
"github.com/documize/community/core/web"
|
||||
)
|
||||
|
||||
|
@ -157,7 +157,7 @@ func setupAccount(completion onboardRequest, serial string) (err error) {
|
|||
password := secrets.GeneratePassword(completion.Password, salt)
|
||||
|
||||
// Allocate organization to the user.
|
||||
orgID := util.UniqueID()
|
||||
orgID := uniqueid.Generate()
|
||||
|
||||
sql := fmt.Sprintf("insert into organization (refid, company, title, message, domain, email, serial) values (\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\")",
|
||||
orgID, completion.Company, completion.CompanyLong, completion.Message, completion.URL, completion.Email, serial)
|
||||
|
@ -168,7 +168,7 @@ func setupAccount(completion onboardRequest, serial string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
userID := util.UniqueID()
|
||||
userID := uniqueid.Generate()
|
||||
|
||||
sql = fmt.Sprintf("insert into user (refid, firstname, lastname, email, initials, salt, password, global) values (\"%s\",\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", 1)",
|
||||
userID, completion.Firstname, completion.Lastname, completion.Email, stringutil.MakeInitials(completion.Firstname, completion.Lastname), salt, password)
|
||||
|
@ -180,7 +180,7 @@ func setupAccount(completion onboardRequest, serial string) (err error) {
|
|||
}
|
||||
|
||||
// Link user to organization.
|
||||
accountID := util.UniqueID()
|
||||
accountID := uniqueid.Generate()
|
||||
sql = fmt.Sprintf("insert into account (refid, userid, orgid, admin, editor) values (\"%s\", \"%s\", \"%s\",1, 1)", accountID, userID, orgID)
|
||||
_, err = runSQL(sql)
|
||||
|
||||
|
@ -190,7 +190,7 @@ func setupAccount(completion onboardRequest, serial string) (err error) {
|
|||
}
|
||||
|
||||
// Set up default labels for main collection.
|
||||
labelID := util.UniqueID()
|
||||
labelID := uniqueid.Generate()
|
||||
sql = fmt.Sprintf("insert into label (refid, orgid, label, type, userid) values (\"%s\", \"%s\", \"My Project\", 2, \"%s\")", labelID, orgID, userID)
|
||||
_, err = runSQL(sql)
|
||||
|
||||
|
@ -198,7 +198,7 @@ func setupAccount(completion onboardRequest, serial string) (err error) {
|
|||
log.Error("insert into label failed", err)
|
||||
}
|
||||
|
||||
labelRoleID := util.UniqueID()
|
||||
labelRoleID := uniqueid.Generate()
|
||||
sql = fmt.Sprintf("insert into labelrole (refid, labelid, orgid, userid, canview, canedit) values (\"%s\", \"%s\", \"%s\", \"%s\", 1, 1)", labelRoleID, labelID, orgID, userID)
|
||||
_, err = runSQL(sql)
|
||||
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
//
|
||||
// https://documize.com
|
||||
|
||||
// Package util provides utility functions specific to the http-end-point component of Documize.
|
||||
package util
|
||||
// Package uniqueid provides utility functions specific to the http-end-point component of Documize.
|
||||
package uniqueid
|
||||
|
||||
import "github.com/rs/xid"
|
||||
|
||||
// UniqueID creates a randomly generated string suitable for use as part of an URI.
|
||||
// Generate creates a randomly generated string suitable for use as part of an URI.
|
||||
// It returns a string that is always 16 characters long.
|
||||
func UniqueID() string {
|
||||
func Generate() string {
|
||||
return xid.New().String()
|
||||
}
|
|
@ -9,14 +9,12 @@
|
|||
//
|
||||
// https://documize.com
|
||||
|
||||
package util_test
|
||||
package uniqueid
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/documize/community/core/api/util"
|
||||
)
|
||||
|
||||
const sample = 1 << 24
|
||||
|
@ -47,7 +45,7 @@ func TestUniqueID(t *testing.T) {
|
|||
for i := 0; i < c; i++ {
|
||||
go func() {
|
||||
for i := 0; i < ss; i++ {
|
||||
mm(t, util.UniqueID())
|
||||
mm(t, Generate())
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
|
@ -57,6 +55,6 @@ func TestUniqueID(t *testing.T) {
|
|||
|
||||
func BenchmarkUniqueID(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
util.UniqueID()
|
||||
Generate()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue