6
6
// you may not use this file except in compliance with the License.
7
7
// You may obtain a copy of the License at
8
8
//
9
- // http://www.apache.org/licenses/LICENSE-2.0
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
10
//
11
11
// Unless required by applicable law or agreed to in writing, software
12
12
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -24,7 +24,7 @@ import (
24
24
"sync"
25
25
"unsafe"
26
26
27
- "github.com/henrylee2cn /ameda"
27
+ "github.com/andeya /ameda"
28
28
)
29
29
30
30
// Internally unified data types
@@ -75,8 +75,9 @@ type fieldVM struct {
75
75
76
76
// New creates a tag expression interpreter that uses tagName as the tag name.
77
77
// 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.
80
81
func New (tagName ... string ) * VM {
81
82
if len (tagName ) == 0 {
82
83
tagName = append (tagName , "" )
@@ -103,9 +104,12 @@ var (
103
104
104
105
// Run returns the tag expression handler of the @structPtrOrReflectValue.
105
106
// 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
+ //
108
111
// Disable new -d=checkptr behaviour for Go 1.14
112
+ //
109
113
//go:nocheckptr
110
114
func (vm * VM ) Run (structPtrOrReflectValue interface {}) (* TagExpr , error ) {
111
115
var v reflect.Value
@@ -150,9 +154,10 @@ func (vm *VM) Run(structPtrOrReflectValue interface{}) (*TagExpr, error) {
150
154
151
155
// RunAny returns the tag expression handler for the @v.
152
156
// 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.
156
161
func (vm * VM ) RunAny (v interface {}, fn func (* TagExpr , error ) error ) error {
157
162
vv , isReflectValue := v .(reflect.Value )
158
163
if ! isReflectValue {
@@ -744,23 +749,26 @@ type TagExpr struct {
744
749
745
750
// EvalFloat evaluates the value of the struct tag expression by the selector expression.
746
751
// NOTE:
747
- // If the expression value type is not float64, return 0.
752
+ //
753
+ // If the expression value type is not float64, return 0.
748
754
func (t * TagExpr ) EvalFloat (exprSelector string ) float64 {
749
755
r , _ := t .Eval (exprSelector ).(float64 )
750
756
return r
751
757
}
752
758
753
759
// EvalString evaluates the value of the struct tag expression by the selector expression.
754
760
// NOTE:
755
- // If the expression value type is not string, return "".
761
+ //
762
+ // If the expression value type is not string, return "".
756
763
func (t * TagExpr ) EvalString (exprSelector string ) string {
757
764
r , _ := t .Eval (exprSelector ).(string )
758
765
return r
759
766
}
760
767
761
768
// EvalBool evaluates the value of the struct tag expression by the selector expression.
762
769
// 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.
764
772
func (t * TagExpr ) EvalBool (exprSelector string ) bool {
765
773
return FakeBool (t .Eval (exprSelector ))
766
774
}
@@ -838,8 +846,9 @@ func (t *TagExpr) RangeFields(fn func(*FieldHandler) bool) bool {
838
846
839
847
// Eval evaluates the value of the struct tag expression by the selector expression.
840
848
// 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
843
852
func (t * TagExpr ) Eval (exprSelector string ) interface {} {
844
853
expr , ok := t .s .exprs [exprSelector ]
845
854
if ! ok {
@@ -866,7 +875,8 @@ func (t *TagExpr) Eval(exprSelector string) interface{} {
866
875
// Range loop through each tag expression.
867
876
// When fn returns false, interrupt traversal and return false.
868
877
// NOTE:
869
- // eval result types: float64, string, bool, nil
878
+ //
879
+ // eval result types: float64, string, bool, nil
870
880
func (t * TagExpr ) Range (fn func (* ExprHandler ) error ) error {
871
881
var err error
872
882
if list := t .s .exprSelectorList ; len (list ) > 0 {
0 commit comments