Skip to content

Commit

Permalink
Merge f083957 into 545ebf7
Browse files Browse the repository at this point in the history
  • Loading branch information
AngLi2 committed Jan 14, 2020
2 parents 545ebf7 + f083957 commit 063ada7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions server/service/mongo/kv/kv_dao.go
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/apache/servicecomb-kie/server/service/mongo/history"
"github.com/apache/servicecomb-kie/server/service/mongo/session"
"github.com/go-mesh/openlogging"
uuid "github.com/satori/go.uuid"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
Expand All @@ -37,7 +36,7 @@ import (
func createKey(ctx context.Context, kv *model.KVDoc) (*model.KVDoc, error) {
collection := session.GetDB().Collection(session.CollectionKV)
var err error
kv.ID = uuid.NewV4().String()
generateId(kv)
revision, err := counter.ApplyRevision(ctx)
if err != nil {
openlogging.Error(err.Error())
Expand Down
13 changes: 13 additions & 0 deletions server/service/mongo/kv/tool.go
Expand Up @@ -20,6 +20,7 @@ package kv
import (
"context"
"github.com/apache/servicecomb-kie/server/service"
uuid "github.com/satori/go.uuid"

"github.com/apache/servicecomb-kie/pkg/model"
"github.com/go-mesh/openlogging"
Expand Down Expand Up @@ -68,3 +69,15 @@ func cursorToOneKV(ctx context.Context, cur *mongo.Cursor, labels map[string]str
}
return nil, service.ErrKeyNotExists
}

//generate unique id by key, labelID and project
func generateId(kv *model.KVDoc) {
kv.ID = nameUUID(kv.Domain, kv.Key, kv.LabelID, kv.Project).String()
}
func nameUUID(salts ...string) (id uuid.UUID) {
base, _ := uuid.FromString("f5394eef-e576-4709-9e4b-a7c231bd34a4")
for _, salt := range salts {
base = uuid.NewV5(base, salt)
}
return base
}

0 comments on commit 063ada7

Please sign in to comment.