Skip to content

Commit

Permalink
chore: henrylee2cn/ameda -> andeya/ameda
Browse files Browse the repository at this point in the history
Change-Id: I8ae395b11e78157acbc4d8df44a62de3f5eee1fe
  • Loading branch information
andeya committed Feb 22, 2023
1 parent 82ef1cf commit a44f579
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 35 deletions.
13 changes: 8 additions & 5 deletions binding/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"
"sync"

"github.com/andeya/ameda"
"github.com/andeya/goutil"
"github.com/henrylee2cn/ameda"

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

// New creates a binding tool.
// NOTE:
// Use default tag name for config fields that are empty
//
// Use default tag name for config fields that are empty
func New(config *Config) *Binding {
if config == nil {
config = new(Config)
Expand All @@ -44,8 +45,9 @@ func New(config *Config) *Binding {
// SetLooseZeroMode if set to true,
// the empty string request parameter is bound to the zero value of parameter.
// NOTE:
// The default is false;
// Suitable for these parameter types: query/header/cookie/form .
//
// The default is false;
// Suitable for these parameter types: query/header/cookie/form .
func (b *Binding) SetLooseZeroMode(enable bool) *Binding {
b.config.LooseZeroMode = enable
for k := range b.recvs {
Expand All @@ -59,7 +61,8 @@ var defaultBindErrFactory = newDefaultErrorFactory("binding")

// SetErrorFactory customizes the factory of validation error.
// NOTE:
// If errFactory==nil, the default is used
//
// If errFactory==nil, the default is used
func (b *Binding) SetErrorFactory(bindErrFactory, validatingErrFactory func(failField, msg string) error) *Binding {
if bindErrFactory == nil {
bindErrFactory = defaultBindErrFactory
Expand Down
2 changes: 1 addition & 1 deletion binding/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"time"

// "github.com/bytedance/go-tagexpr/v2/binding/gjson"
"github.com/andeya/ameda"
"github.com/andeya/goutil/httpbody"
vd "github.com/bytedance/go-tagexpr/v2/validator"
"github.com/davecgh/go-spew/spew"
"github.com/henrylee2cn/ameda"
"github.com/stretchr/testify/assert"

"github.com/bytedance/go-tagexpr/v2/binding"
Expand Down
5 changes: 3 additions & 2 deletions binding/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"reflect"
"time"

"github.com/henrylee2cn/ameda"
"github.com/andeya/ameda"
"google.golang.org/protobuf/proto"
)

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

// MustRegTypeUnmarshal registers unmarshalor function of type.
// NOTE:
// panic if exist error.
//
// panic if exist error.
func MustRegTypeUnmarshal(t reflect.Type, fn func(v string, emptyAsZero bool) (reflect.Value, error)) {
err := RegTypeUnmarshal(t, fn)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions binding/gjson/gjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"reflect"
"strings"

"github.com/andeya/ameda"
"github.com/andeya/goutil"
"github.com/henrylee2cn/ameda"
"github.com/tidwall/gjson"

"github.com/bytedance/go-tagexpr/v2/binding"
Expand All @@ -39,7 +39,7 @@ import (
)

var (
programCache = caching.CreateProgramCache()
programCache = caching.CreateProgramCache()
unmarshalerInterface = reflect.TypeOf((*json.Unmarshaler)(nil)).Elem()
)

Expand Down
3 changes: 1 addition & 2 deletions binding/gjson/gjson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"sync"
"testing"

"github.com/henrylee2cn/ameda"
"github.com/andeya/ameda"
"github.com/stretchr/testify/assert"

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


// MarshalJSON to output non base64 encoded []byte
func (j ByteSlice) MarshalJSON() ([]byte, error) {
if len(j) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion binding/param_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strconv"
"strings"

"github.com/henrylee2cn/ameda"
"github.com/andeya/ameda"
"github.com/tidwall/gjson"

"github.com/bytedance/go-tagexpr/v2"
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/bytedance/go-tagexpr/v2
go 1.14

require (
github.com/andeya/goutil v0.0.0-20220704075712-42f2ec55fe8d
github.com/andeya/ameda v1.5.3
github.com/andeya/goutil v1.0.1
github.com/davecgh/go-spew v1.1.1
github.com/henrylee2cn/ameda v1.5.1
github.com/nyaruka/phonenumbers v1.0.55
github.com/stretchr/testify v1.7.5
github.com/tidwall/gjson v1.9.3
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/andeya/goutil v0.0.0-20220704075712-42f2ec55fe8d h1:qZjX5KRJDCA0DaORmzyXuySdlT+MOhx0OOTbUbdPxp0=
github.com/andeya/goutil v0.0.0-20220704075712-42f2ec55fe8d/go.mod h1:jEG5/QnnhG7yGxwFUX6Q+JGMif7sjdHmmNVjn7nhJDo=
github.com/andeya/ameda v1.5.3 h1:SvqnhQPZwwabS8HQTRGfJwWPl2w9ZIPInHAw9aE1Wlk=
github.com/andeya/ameda v1.5.3/go.mod h1:FQDHRe1I995v6GG+8aJ7UIUToEmbdTJn/U26NCPIgXQ=
github.com/andeya/goutil v1.0.1 h1:eiYwVyAnnK0dXU5FJsNjExkJW4exUGn/xefPt3k4eXg=
github.com/andeya/goutil v1.0.1/go.mod h1:jEG5/QnnhG7yGxwFUX6Q+JGMif7sjdHmmNVjn7nhJDo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -8,8 +10,6 @@ github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/henrylee2cn/ameda v1.5.1 h1:4n25dZyVSAgRCJ4DLLYF65ynwr9RYO92oFbdyUJWAFk=
github.com/henrylee2cn/ameda v1.5.1/go.mod h1:wnTERseg26LtcSrHOPlV3pBGnNwQiz3TNIeMEgNoNlg=
github.com/nyaruka/phonenumbers v1.0.55 h1:bj0nTO88Y68KeUQ/n3Lo2KgK7lM1hF7L9NFuwcCl3yg=
github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
2 changes: 1 addition & 1 deletion spec_operand.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strconv"
"strings"

"github.com/henrylee2cn/ameda"
"github.com/andeya/ameda"
)

// --------------------------- Operand ---------------------------
Expand Down
40 changes: 25 additions & 15 deletions tagexpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -24,7 +24,7 @@ import (
"sync"
"unsafe"

"github.com/henrylee2cn/ameda"
"github.com/andeya/ameda"
)

// Internally unified data types
Expand Down Expand Up @@ -75,8 +75,9 @@ type fieldVM struct {

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

// Run returns the tag expression handler of the @structPtrOrReflectValue.
// NOTE:
// If the structure type has not been warmed up,
// it will be slower when it is first called.
//
// If the structure type has not been warmed up,
// it will be slower when it is first called.
//
// Disable new -d=checkptr behaviour for Go 1.14
//
//go:nocheckptr
func (vm *VM) Run(structPtrOrReflectValue interface{}) (*TagExpr, error) {
var v reflect.Value
Expand Down Expand Up @@ -150,9 +154,10 @@ func (vm *VM) Run(structPtrOrReflectValue interface{}) (*TagExpr, error) {

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

// EvalFloat evaluates the value of the struct tag expression by the selector expression.
// NOTE:
// If the expression value type is not float64, return 0.
//
// If the expression value type is not float64, return 0.
func (t *TagExpr) EvalFloat(exprSelector string) float64 {
r, _ := t.Eval(exprSelector).(float64)
return r
}

// EvalString evaluates the value of the struct tag expression by the selector expression.
// NOTE:
// If the expression value type is not string, return "".
//
// If the expression value type is not string, return "".
func (t *TagExpr) EvalString(exprSelector string) string {
r, _ := t.Eval(exprSelector).(string)
return r
}

// EvalBool evaluates the value of the struct tag expression by the selector expression.
// NOTE:
// If the expression value is not 0, '' or nil, return true.
//
// If the expression value is not 0, '' or nil, return true.
func (t *TagExpr) EvalBool(exprSelector string) bool {
return FakeBool(t.Eval(exprSelector))
}
Expand Down Expand Up @@ -838,8 +846,9 @@ func (t *TagExpr) RangeFields(fn func(*FieldHandler) bool) bool {

// Eval evaluates the value of the struct tag expression by the selector expression.
// NOTE:
// format: fieldName, fieldName.exprName, fieldName1.fieldName2.exprName1
// result types: float64, string, bool, nil
//
// format: fieldName, fieldName.exprName, fieldName1.fieldName2.exprName1
// result types: float64, string, bool, nil
func (t *TagExpr) Eval(exprSelector string) interface{} {
expr, ok := t.s.exprs[exprSelector]
if !ok {
Expand All @@ -866,7 +875,8 @@ func (t *TagExpr) Eval(exprSelector string) interface{} {
// Range loop through each tag expression.
// When fn returns false, interrupt traversal and return false.
// NOTE:
// eval result types: float64, string, bool, nil
//
// eval result types: float64, string, bool, nil
func (t *TagExpr) Range(fn func(*ExprHandler) error) error {
var err error
if list := t.s.exprSelectorList; len(list) > 0 {
Expand Down
10 changes: 10 additions & 0 deletions validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,13 @@ func TestIssue31(t *testing.T) {
assert.EqualError(t, vd.Validate(&TStruct{A: []int32{1}}), "syntax error: \"($ != nil && range($, in(#v, 1, 2, 3))\"")
assert.EqualError(t, vd.Validate(&TStruct{A: []int32{1}}), "syntax error: \"($ != nil && range($, in(#v, 1, 2, 3))\"")
}

func TestRegexp(t *testing.T) {
type TStruct struct {
A string `vd:"regexp('(\\d+\\.){3}\\d+')"`
}
assert.NoError(t, vd.Validate(&TStruct{A: "0.0.0.0"}))
assert.EqualError(t, vd.Validate(&TStruct{A: "0...0"}), "invalid parameter: A")
assert.EqualError(t, vd.Validate(&TStruct{A: "abc1"}), "invalid parameter: A")
assert.EqualError(t, vd.Validate(&TStruct{A: "0?0?0?0"}), "invalid parameter: A")
}

0 comments on commit a44f579

Please sign in to comment.