[add] process utils.str.UUID
This commit is contained in:
parent
2a36edf891
commit
2f77721d00
3 changed files with 19 additions and 0 deletions
|
|
@ -53,6 +53,7 @@ func init() {
|
||||||
process.Alias("xiang.helper.HexToString", "utils.str.Hex")
|
process.Alias("xiang.helper.HexToString", "utils.str.Hex")
|
||||||
process.Register("utils.str.Join", str.ProcessJoin)
|
process.Register("utils.str.Join", str.ProcessJoin)
|
||||||
process.Register("utils.str.JoinPath", str.ProcessJoinPath)
|
process.Register("utils.str.JoinPath", str.ProcessJoinPath)
|
||||||
|
process.Register("utils.str.UUID", str.ProcessUUID)
|
||||||
|
|
||||||
// Array
|
// Array
|
||||||
process.Alias("xiang.helper.ArrayPluck", "utils.arr.Pluck")
|
process.Alias("xiang.helper.ArrayPluck", "utils.arr.Pluck")
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/yaoapp/gou/process"
|
"github.com/yaoapp/gou/process"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -29,3 +30,9 @@ func ProcessJoinPath(process *process.Process) interface{} {
|
||||||
}
|
}
|
||||||
return filepath.Join(paths...)
|
return filepath.Join(paths...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProcessUUID utils.str.uuid
|
||||||
|
func ProcessUUID(process *process.Process) interface{} {
|
||||||
|
uuid := uuid.New()
|
||||||
|
return uuid.String()
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/yaoapp/gou/process"
|
"github.com/yaoapp/gou/process"
|
||||||
_ "github.com/yaoapp/yao/helper"
|
_ "github.com/yaoapp/yao/helper"
|
||||||
|
|
@ -21,6 +22,16 @@ func TestProcessStrJoinPath(t *testing.T) {
|
||||||
assert.Equal(t, shouldBe, res)
|
assert.Equal(t, shouldBe, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProcessUUID(t *testing.T) {
|
||||||
|
res := process.New("utils.str.UUID").Run().(string)
|
||||||
|
_, err := uuid.Parse(res)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, 36, len(res))
|
||||||
|
}
|
||||||
|
|
||||||
func TestProcessStrHex(t *testing.T) {
|
func TestProcessStrHex(t *testing.T) {
|
||||||
res, err := process.New("utils.str.Hex", []byte{0x0, 0x1}).Exec()
|
res, err := process.New("utils.str.Hex", []byte{0x0, 0x1}).Exec()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue