From 650150d42c802cb915ad40ed3d2ad61a195f7d58 Mon Sep 17 00:00:00 2001 From: Tong Li Date: Thu, 30 Jan 2020 05:05:07 +0000 Subject: [PATCH] Added uuid parameter type Signed-off-by: Tong Li --- modules/gosdk/Gopkg.lock | 9 +++++++++ modules/gosdk/Gopkg.toml | 6 +++++- modules/gosdk/utilities/paramGenerator.go | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/modules/gosdk/Gopkg.lock b/modules/gosdk/Gopkg.lock index 4681c12..264b208 100644 --- a/modules/gosdk/Gopkg.lock +++ b/modules/gosdk/Gopkg.lock @@ -117,6 +117,14 @@ pruneopts = "NUT" revision = "5ab67e519c93568ac3ee50fd6772a5bcf8aa460d" +[[projects]] + digest = "1:ab3ec1fe3e39bac4b3ab63390767766622be35b7cab03f47f787f9ec60522a53" + name = "github.com/google/uuid" + packages = ["."] + pruneopts = "NUT" + revision = "0cd6bf5da1e1c83f8b45653022c74f71af0538a4" + version = "v1.1.1" + [[projects]] digest = "1:11c6c696067d3127ecf332b10f89394d386d9083f82baf71f40f2da31841a009" name = "github.com/hashicorp/hcl" @@ -683,6 +691,7 @@ "github.com/golang/protobuf/jsonpb", "github.com/golang/protobuf/proto", "github.com/golang/protobuf/ptypes/timestamp", + "github.com/google/uuid", "github.com/hyperledger/fabric-sdk-go/pkg/client/channel", "github.com/hyperledger/fabric-sdk-go/pkg/client/channel/invoke", "github.com/hyperledger/fabric-sdk-go/pkg/client/common/discovery/dynamicdiscovery", diff --git a/modules/gosdk/Gopkg.toml b/modules/gosdk/Gopkg.toml index 14c9b64..e27d17f 100755 --- a/modules/gosdk/Gopkg.toml +++ b/modules/gosdk/Gopkg.toml @@ -3,7 +3,7 @@ # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md # for detailed Gopkg.toml documentation. # -# required = ["github.com/user/thing/cmd/thing"] +required = ["github.com/google/uuid"] # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] # # [[constraint]] @@ -40,6 +40,10 @@ name = "github.com/hyperledger/fabric" version = "1.4.0" +[[constraint]] + name = "github.com/google/uuid" + version = "1.1.1" + [[constraint]] name = "github.com/xixuejia/viper" branch = "master" diff --git a/modules/gosdk/utilities/paramGenerator.go b/modules/gosdk/utilities/paramGenerator.go index ac77186..9eb28d5 100644 --- a/modules/gosdk/utilities/paramGenerator.go +++ b/modules/gosdk/utilities/paramGenerator.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "github.com/pkg/errors" + "github.com/google/uuid" "hfrd/modules/gosdk/common" "math/rand" "strconv" @@ -13,6 +14,7 @@ import ( const ( LITERAL_PARAM = "literal" + UUID_PARAM = "uuid" STRING_PATTERN = "stringPattern" INTEGER_RANGE = "intRange" PAYLOAD_RANGE = "payloadRange" @@ -43,6 +45,14 @@ type PayloadRange struct { Max string } +type UUID struct { +} + +func (p *UUID) GetValue() string { + id, _ := uuid.NewRandom() + return strings.Replace(id.String(), "-", "", -1) +} + func (p *Literal) GetValue() string { return p.Value } @@ -126,6 +136,12 @@ func GetComplexArgs(complexParams []string, loopIndex int) ([]string, error) { } literal := &Literal{paramKV[1]} arg = literal.GetValue() + case UUID_PARAM: + if len(paramKV) != 1 { + return nil, errors.Errorf("uuid type should contains 1 param") + } + uuidgt := &UUID{} + arg = uuidgt.GetValue() case STRING_PATTERN: if len(paramKV) != 2 { return nil, errors.Errorf("stringPattern type should contains 2 params") @@ -189,6 +205,12 @@ func GetTransientMap(complexParams []string, loopIndex int) ([]byte, error) { } literal := &Literal{paramKV[2]} arg = literal.GetValue() + case UUID_PARAM: + if len(paramKV) != 1 { + return nil, errors.Errorf("uuid type should contains 1 param") + } + uuidgt := &UUID{} + arg = uuidgt.GetValue() case STRING_PATTERN: if len(paramKV) != 3 { return nil, errors.Errorf("stringPattern type should contains 2 params")