Skip to content

Commit

Permalink
Prefix Ids (#58)
Browse files Browse the repository at this point in the history
* prefixes

* fix prefixes
  • Loading branch information
subroseio authored Dec 3, 2023
1 parent 951e92e commit 1fdda98
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions vault/id.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package vault

import (
"fmt"

"github.com/segmentio/ksuid"
)

func GenerateId() string {
func GenerateId(prefix string) string {
ksuid := ksuid.New()
return ksuid.String()
return fmt.Sprintf("%s_%s", prefix, ksuid.String())

}
2 changes: 1 addition & 1 deletion vault/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (st SqlStore) CreateRecords(ctx context.Context, collectionName string, rec
return nil, &ValueError{fmt.Sprintf("expected %d fields, got %d", len(fields), len(record))}
}

recordId := GenerateId()
recordId := GenerateId("rec")
recordIds[i] = recordId

values := make([]interface{}, len(fields)+1)
Expand Down
2 changes: 1 addition & 1 deletion vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ func (vault Vault) CreateToken(ctx context.Context, principal Principal, collect
return "", err
}

tokenId := GenerateId()
tokenId := GenerateId("tok")
for recordId := range records {
err := vault.Db.CreateToken(ctx, tokenId, fmt.Sprintf("%s/%s/%s/%s", collectionName, recordId, fieldName, returnFormat))
if err != nil {
Expand Down

0 comments on commit 1fdda98

Please sign in to comment.