Skip to content

Commit a44f579

Browse files
committed
chore: henrylee2cn/ameda -> andeya/ameda
Change-Id: I8ae395b11e78157acbc4d8df44a62de3f5eee1fe
1 parent 82ef1cf commit a44f579

11 files changed

+58
-35
lines changed

binding/bind.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"strings"
99
"sync"
1010

11+
"github.com/andeya/ameda"
1112
"github.com/andeya/goutil"
12-
"github.com/henrylee2cn/ameda"
1313

1414
"github.com/bytedance/go-tagexpr/v2"
1515
"github.com/bytedance/go-tagexpr/v2/validator"
@@ -27,7 +27,8 @@ type Binding struct {
2727

2828
// New creates a binding tool.
2929
// NOTE:
30-
// Use default tag name for config fields that are empty
30+
//
31+
// Use default tag name for config fields that are empty
3132
func New(config *Config) *Binding {
3233
if config == nil {
3334
config = new(Config)
@@ -44,8 +45,9 @@ func New(config *Config) *Binding {
4445
// SetLooseZeroMode if set to true,
4546
// the empty string request parameter is bound to the zero value of parameter.
4647
// NOTE:
47-
// The default is false;
48-
// Suitable for these parameter types: query/header/cookie/form .
48+
//
49+
// The default is false;
50+
// Suitable for these parameter types: query/header/cookie/form .
4951
func (b *Binding) SetLooseZeroMode(enable bool) *Binding {
5052
b.config.LooseZeroMode = enable
5153
for k := range b.recvs {
@@ -59,7 +61,8 @@ var defaultBindErrFactory = newDefaultErrorFactory("binding")
5961

6062
// SetErrorFactory customizes the factory of validation error.
6163
// NOTE:
62-
// If errFactory==nil, the default is used
64+
//
65+
// If errFactory==nil, the default is used
6366
func (b *Binding) SetErrorFactory(bindErrFactory, validatingErrFactory func(failField, msg string) error) *Binding {
6467
if bindErrFactory == nil {
6568
bindErrFactory = defaultBindErrFactory

binding/bind_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
"time"
1515

1616
// "github.com/bytedance/go-tagexpr/v2/binding/gjson"
17+
"github.com/andeya/ameda"
1718
"github.com/andeya/goutil/httpbody"
1819
vd "github.com/bytedance/go-tagexpr/v2/validator"
1920
"github.com/davecgh/go-spew/spew"
20-
"github.com/henrylee2cn/ameda"
2121
"github.com/stretchr/testify/assert"
2222

2323
"github.com/bytedance/go-tagexpr/v2/binding"

binding/func.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"reflect"
88
"time"
99

10-
"github.com/henrylee2cn/ameda"
10+
"github.com/andeya/ameda"
1111
"google.golang.org/protobuf/proto"
1212
)
1313

@@ -73,7 +73,8 @@ func unmarshal(b []byte, i interface{}) error {
7373

7474
// MustRegTypeUnmarshal registers unmarshalor function of type.
7575
// NOTE:
76-
// panic if exist error.
76+
//
77+
// panic if exist error.
7778
func MustRegTypeUnmarshal(t reflect.Type, fn func(v string, emptyAsZero bool) (reflect.Value, error)) {
7879
err := RegTypeUnmarshal(t, fn)
7980
if err != nil {

binding/gjson/gjson.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
"reflect"
3030
"strings"
3131

32+
"github.com/andeya/ameda"
3233
"github.com/andeya/goutil"
33-
"github.com/henrylee2cn/ameda"
3434
"github.com/tidwall/gjson"
3535

3636
"github.com/bytedance/go-tagexpr/v2/binding"
@@ -39,7 +39,7 @@ import (
3939
)
4040

4141
var (
42-
programCache = caching.CreateProgramCache()
42+
programCache = caching.CreateProgramCache()
4343
unmarshalerInterface = reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()
4444
)
4545

binding/gjson/gjson_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"sync"
99
"testing"
1010

11-
"github.com/henrylee2cn/ameda"
11+
"github.com/andeya/ameda"
1212
"github.com/stretchr/testify/assert"
1313

1414
"github.com/bytedance/go-tagexpr/v2/binding/gjson/internal/rt"
@@ -237,7 +237,6 @@ func getFiledInfoWithMap(t reflect.Type) map[string][]int {
237237
return sf
238238
}
239239

240-
241240
// MarshalJSON to output non base64 encoded []byte
242241
func (j ByteSlice) MarshalJSON() ([]byte, error) {
243242
if len(j) == 0 {

binding/param_info.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"strconv"
1212
"strings"
1313

14-
"github.com/henrylee2cn/ameda"
14+
"github.com/andeya/ameda"
1515
"github.com/tidwall/gjson"
1616

1717
"github.com/bytedance/go-tagexpr/v2"

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module github.com/bytedance/go-tagexpr/v2
33
go 1.14
44

55
require (
6-
github.com/andeya/goutil v0.0.0-20220704075712-42f2ec55fe8d
6+
github.com/andeya/ameda v1.5.3
7+
github.com/andeya/goutil v1.0.1
78
github.com/davecgh/go-spew v1.1.1
8-
github.com/henrylee2cn/ameda v1.5.1
99
github.com/nyaruka/phonenumbers v1.0.55
1010
github.com/stretchr/testify v1.7.5
1111
github.com/tidwall/gjson v1.9.3

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
github.com/andeya/goutil v0.0.0-20220704075712-42f2ec55fe8d h1:qZjX5KRJDCA0DaORmzyXuySdlT+MOhx0OOTbUbdPxp0=
2-
github.com/andeya/goutil v0.0.0-20220704075712-42f2ec55fe8d/go.mod h1:jEG5/QnnhG7yGxwFUX6Q+JGMif7sjdHmmNVjn7nhJDo=
1+
github.com/andeya/ameda v1.5.3 h1:SvqnhQPZwwabS8HQTRGfJwWPl2w9ZIPInHAw9aE1Wlk=
2+
github.com/andeya/ameda v1.5.3/go.mod h1:FQDHRe1I995v6GG+8aJ7UIUToEmbdTJn/U26NCPIgXQ=
3+
github.com/andeya/goutil v1.0.1 h1:eiYwVyAnnK0dXU5FJsNjExkJW4exUGn/xefPt3k4eXg=
4+
github.com/andeya/goutil v1.0.1/go.mod h1:jEG5/QnnhG7yGxwFUX6Q+JGMif7sjdHmmNVjn7nhJDo=
35
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
46
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
57
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -8,8 +10,6 @@ github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4
810
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
911
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
1012
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
11-
github.com/henrylee2cn/ameda v1.5.1 h1:4n25dZyVSAgRCJ4DLLYF65ynwr9RYO92oFbdyUJWAFk=
12-
github.com/henrylee2cn/ameda v1.5.1/go.mod h1:wnTERseg26LtcSrHOPlV3pBGnNwQiz3TNIeMEgNoNlg=
1313
github.com/nyaruka/phonenumbers v1.0.55 h1:bj0nTO88Y68KeUQ/n3Lo2KgK7lM1hF7L9NFuwcCl3yg=
1414
github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U=
1515
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

spec_operand.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"strconv"
2323
"strings"
2424

25-
"github.com/henrylee2cn/ameda"
25+
"github.com/andeya/ameda"
2626
)
2727

2828
// --------------------------- Operand ---------------------------

tagexpr.go

+25-15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -24,7 +24,7 @@ import (
2424
"sync"
2525
"unsafe"
2626

27-
"github.com/henrylee2cn/ameda"
27+
"github.com/andeya/ameda"
2828
)
2929

3030
// Internally unified data types
@@ -75,8 +75,9 @@ type fieldVM struct {
7575

7676
// New creates a tag expression interpreter that uses tagName as the tag name.
7777
// NOTE:
78-
// If no tagName is specified, no tag expression will be interpreted,
79-
// but still can operate the various fields.
78+
//
79+
// If no tagName is specified, no tag expression will be interpreted,
80+
// but still can operate the various fields.
8081
func New(tagName ...string) *VM {
8182
if len(tagName) == 0 {
8283
tagName = append(tagName, "")
@@ -103,9 +104,12 @@ var (
103104

104105
// Run returns the tag expression handler of the @structPtrOrReflectValue.
105106
// NOTE:
106-
// If the structure type has not been warmed up,
107-
// it will be slower when it is first called.
107+
//
108+
// If the structure type has not been warmed up,
109+
// it will be slower when it is first called.
110+
//
108111
// Disable new -d=checkptr behaviour for Go 1.14
112+
//
109113
//go:nocheckptr
110114
func (vm *VM) Run(structPtrOrReflectValue interface{}) (*TagExpr, error) {
111115
var v reflect.Value
@@ -150,9 +154,10 @@ func (vm *VM) Run(structPtrOrReflectValue interface{}) (*TagExpr, error) {
150154

151155
// RunAny returns the tag expression handler for the @v.
152156
// NOTE:
153-
// The @v can be structured data such as struct, map, slice, array, interface, reflcet.Value, etc.
154-
// If the structure type has not been warmed up,
155-
// it will be slower when it is first called.
157+
//
158+
// The @v can be structured data such as struct, map, slice, array, interface, reflcet.Value, etc.
159+
// If the structure type has not been warmed up,
160+
// it will be slower when it is first called.
156161
func (vm *VM) RunAny(v interface{}, fn func(*TagExpr, error) error) error {
157162
vv, isReflectValue := v.(reflect.Value)
158163
if !isReflectValue {
@@ -744,23 +749,26 @@ type TagExpr struct {
744749

745750
// EvalFloat evaluates the value of the struct tag expression by the selector expression.
746751
// NOTE:
747-
// If the expression value type is not float64, return 0.
752+
//
753+
// If the expression value type is not float64, return 0.
748754
func (t *TagExpr) EvalFloat(exprSelector string) float64 {
749755
r, _ := t.Eval(exprSelector).(float64)
750756
return r
751757
}
752758

753759
// EvalString evaluates the value of the struct tag expression by the selector expression.
754760
// NOTE:
755-
// If the expression value type is not string, return "".
761+
//
762+
// If the expression value type is not string, return "".
756763
func (t *TagExpr) EvalString(exprSelector string) string {
757764
r, _ := t.Eval(exprSelector).(string)
758765
return r
759766
}
760767

761768
// EvalBool evaluates the value of the struct tag expression by the selector expression.
762769
// NOTE:
763-
// If the expression value is not 0, '' or nil, return true.
770+
//
771+
// If the expression value is not 0, '' or nil, return true.
764772
func (t *TagExpr) EvalBool(exprSelector string) bool {
765773
return FakeBool(t.Eval(exprSelector))
766774
}
@@ -838,8 +846,9 @@ func (t *TagExpr) RangeFields(fn func(*FieldHandler) bool) bool {
838846

839847
// Eval evaluates the value of the struct tag expression by the selector expression.
840848
// NOTE:
841-
// format: fieldName, fieldName.exprName, fieldName1.fieldName2.exprName1
842-
// result types: float64, string, bool, nil
849+
//
850+
// format: fieldName, fieldName.exprName, fieldName1.fieldName2.exprName1
851+
// result types: float64, string, bool, nil
843852
func (t *TagExpr) Eval(exprSelector string) interface{} {
844853
expr, ok := t.s.exprs[exprSelector]
845854
if !ok {
@@ -866,7 +875,8 @@ func (t *TagExpr) Eval(exprSelector string) interface{} {
866875
// Range loop through each tag expression.
867876
// When fn returns false, interrupt traversal and return false.
868877
// NOTE:
869-
// eval result types: float64, string, bool, nil
878+
//
879+
// eval result types: float64, string, bool, nil
870880
func (t *TagExpr) Range(fn func(*ExprHandler) error) error {
871881
var err error
872882
if list := t.s.exprSelectorList; len(list) > 0 {

validator/validator_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,13 @@ func TestIssue31(t *testing.T) {
299299
assert.EqualError(t, vd.Validate(&TStruct{A: []int32{1}}), "syntax error: \"($ != nil && range($, in(#v, 1, 2, 3))\"")
300300
assert.EqualError(t, vd.Validate(&TStruct{A: []int32{1}}), "syntax error: \"($ != nil && range($, in(#v, 1, 2, 3))\"")
301301
}
302+
303+
func TestRegexp(t *testing.T) {
304+
type TStruct struct {
305+
A string `vd:"regexp('(\\d+\\.){3}\\d+')"`
306+
}
307+
assert.NoError(t, vd.Validate(&TStruct{A: "0.0.0.0"}))
308+
assert.EqualError(t, vd.Validate(&TStruct{A: "0...0"}), "invalid parameter: A")
309+
assert.EqualError(t, vd.Validate(&TStruct{A: "abc1"}), "invalid parameter: A")
310+
assert.EqualError(t, vd.Validate(&TStruct{A: "0?0?0?0"}), "invalid parameter: A")
311+
}

0 commit comments

Comments
 (0)