Skip to content

Commit

Permalink
[feat]return the same ID when input the same kvDoc request
Browse files Browse the repository at this point in the history
  • Loading branch information
little-cui committed Sep 19, 2022
1 parent efeb332 commit 729af4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pkg/model/db_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type PollingDetail struct {

// UpdateKVRequest is db struct, it contains kv update request params
type UpdateKVRequest struct {
ID string `json:"id,omitempty" bson:"id,omitempty" yaml:"id,omitempty" swag:"string" validate:"uuid"`
ID string `json:"id,omitempty" bson:"id,omitempty" yaml:"id,omitempty" swag:"string"`
Value string `json:"value,omitempty" yaml:"value,omitempty" validate:"max=131072,value"`
Project string `json:"project,omitempty" yaml:"project,omitempty" validate:"min=1,max=256,commonName"`
Domain string `json:"domain,omitempty" yaml:"domain,omitempty" validate:"min=1,max=256,commonName"` //redundant
Expand All @@ -87,7 +87,7 @@ type UpdateKVRequest struct {
type GetKVRequest struct {
Project string `json:"project,omitempty" yaml:"project,omitempty" validate:"min=1,max=256,commonName"`
Domain string `json:"domain,omitempty" yaml:"domain,omitempty" validate:"min=1,max=256,commonName"` //redundant
ID string `json:"id,omitempty" bson:"id,omitempty" yaml:"id,omitempty" swag:"string" validate:"uuid"`
ID string `json:"id,omitempty" bson:"id,omitempty" yaml:"id,omitempty" swag:"string"`
}

// ListKVRequest contains kv list request params
Expand Down
25 changes: 13 additions & 12 deletions server/service/kv/kv_svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ package kv

import (
"context"
"crypto/sha256"
"fmt"
"strings"
"time"

"github.com/go-chassis/cari/config"
"github.com/go-chassis/cari/pkg/errsvc"
"github.com/go-chassis/foundation/validator"
"github.com/go-chassis/go-chassis/v2/pkg/backends/quota"
"github.com/go-chassis/openlog"
"github.com/gofrs/uuid"

"github.com/apache/servicecomb-kie/pkg/common"
"github.com/apache/servicecomb-kie/pkg/concurrency"
"github.com/apache/servicecomb-kie/pkg/model"
"github.com/apache/servicecomb-kie/pkg/stringutil"
"github.com/apache/servicecomb-kie/server/datasource"
"github.com/apache/servicecomb-kie/server/pubsub"
"github.com/apache/servicecomb-kie/server/service/sync"
"github.com/go-chassis/cari/config"
"github.com/go-chassis/cari/pkg/errsvc"
"github.com/go-chassis/foundation/validator"
"github.com/go-chassis/go-chassis/v2/pkg/backends/quota"
"github.com/go-chassis/openlog"
)

var listSema = concurrency.NewSemaphore(concurrency.DefaultConcurrency)
Expand Down Expand Up @@ -131,11 +131,12 @@ func Create(ctx context.Context, kv *model.KVDoc) (*model.KVDoc, *errsvc.Error)
}

func completeKV(kv *model.KVDoc, revision int64) error {
id, err := uuid.NewV4()
if err != nil {
return err
}
kv.ID = id.String()
kv.ID = fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join([]string{
kv.Domain,
kv.Project,
kv.Key,
kv.LabelFormat,
}, "/"))))
kv.UpdateRevision = revision
kv.CreateRevision = revision
now := time.Now().Unix()
Expand Down

0 comments on commit 729af4d

Please sign in to comment.