提交 5d4d5dd9 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

gen uuid

上级 b92b4a5c
......@@ -13,12 +13,12 @@ fields:
range: 10-20
format: sha1
prefix: "sha1: "
postfix: " "
postfix: " "
- field: field_3_base64
range: 10-20
format: base64
prefix: "base64: "
prefix: "base64: "
postfix: "\t"
- field: field_4
......@@ -30,3 +30,8 @@ fields:
format: urlencode
prefix: "urlencode: "
postfix: "\t"
- field: field_5_uuid
format: "uuid()"
prefix: "uuid: "
postfix: " "
\ No newline at end of file
......@@ -5,12 +5,7 @@ author: zentao
version: 1.0
fields:
- field: length32_random_no_separator2
use: length32_random_no_separator
from: uuid.v1.yaml
postfix: " "
- field: length162
use: length16
from: uuid.v1.yaml
- field: f1
range: 0-9
loop: 2-4
postfix: " "
......@@ -41,6 +41,7 @@ require (
github.com/pierrec/lz4/v4 v4.1.3 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/robfig/cron/v3 v3.0.1
github.com/satori/go.uuid v1.2.0 // indirect
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.7.0 // indirect
......
......@@ -242,7 +242,8 @@ func GenerateValuesForField(field *model.DefField) []string {
for {
// 2. random replacement
isRandomAndLoopEnd := !vari.ResLoading && // ignore rand in resource
!(*field).ReferToAnotherYaml && (*field).IsRand && (*field).LoopIndex == (*field).LoopEnd
!(*field).ReferToAnotherYaml &&
(*field).IsRand && (*field).LoopIndex > (*field).LoopEnd
// isNotRandomAndValOver := !(*field).IsRand && indexOfRow >= len(fieldWithValues.Values)
if count >= vari.Total || count >= len(fieldWithValues.Values) || isRandomAndLoopEnd {
for _, v := range fieldWithValues.Values {
......
......@@ -36,7 +36,10 @@ func CreateListFieldValues(field *model.DefField, fieldValue *model.FieldWithVal
func CreateFieldValuesFromList(field *model.DefField, fieldValue *model.FieldWithValues) {
rang := field.Range
if rang == "" {
fieldValue.Values = append(fieldValue.Values, "")
for i := 0; i < vari.Total; i++ {
fieldValue.Values = append(fieldValue.Values, "")
}
return
}
......
package main
import (
"encoding/base64"
"log"
"net/url"
"fmt"
uuid "github.com/satori/go.uuid"
)
func main() {
str := "http://baidu.com"
log.Println(base64.StdEncoding.EncodeToString([]byte(str)))
log.Println(url.QueryEscape(str))
u1 := uuid.NewV4()
fmt.Printf("UUIDv4: %s\n", u1)
u1 = uuid.NewV4()
fmt.Printf("UUIDv4: %s\n", u1)
u1 = uuid.NewV4()
fmt.Printf("UUIDv4: %s\n", u1)
}
......@@ -12,6 +12,7 @@ import (
"github.com/easysoft/zendata/src/model"
constant "github.com/easysoft/zendata/src/utils/const"
"github.com/mattn/go-runewidth"
uuid "github.com/satori/go.uuid"
"gopkg.in/yaml.v2"
"net/url"
"regexp"
......@@ -128,6 +129,10 @@ func FormatStr(format string, val interface{}, precision int) (ret string, pass
ret = UrlEncode(str)
pass = true
return
} else if strings.Index(format, "uuid()") == 0 {
ret = uuid.NewV4().String()
pass = true
return
}
str := fmt.Sprintf(format, val)
......
无法预览此类型文件
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册