File tree Expand file tree Collapse file tree 2 files changed +64
-3
lines changed Expand file tree Collapse file tree 2 files changed +64
-3
lines changed Original file line number Diff line number Diff line change
1
+ package operator
2
+
3
+ // import (
4
+ // "reflect"
5
+ // "strings"
6
+ // )
7
+
8
+ func init () {
9
+ AddOperator (BeginsWith )
10
+ }
11
+
12
+ var BeginsWith = & Operator {
13
+ Name : "begins_with" ,
14
+ Evaluate : func (input , value interface {}) bool {
15
+ return false
16
+ },
17
+ }
Original file line number Diff line number Diff line change 1
1
package querybuilder
2
2
3
3
import (
4
+ "fmt"
4
5
"reflect"
6
+ "strconv"
5
7
"strings"
6
8
"sync"
7
9
@@ -87,11 +89,11 @@ func (r *Rule) castValue(v interface{}) interface{} {
87
89
88
90
switch r .Type {
89
91
case "string" :
90
- return v .( string )
92
+ return to_string ( v )
91
93
case "integer" :
92
- return int ( v .( float64 ) )
94
+ return to_integer ( v )
93
95
case "double" :
94
- return v .( float64 )
96
+ return to_double ( v )
95
97
case "date" :
96
98
return nil
97
99
case "time" :
@@ -120,3 +122,45 @@ func (r *Rule) parseValue(v interface{}) interface{} {
120
122
121
123
return r .castValue (v )
122
124
}
125
+
126
+ func to_string (v interface {}) string {
127
+ switch v .(type ) {
128
+ case string :
129
+ return v .(string )
130
+ case float64 :
131
+ return fmt .Sprintf ("%f" , v .(float64 ))
132
+ case bool :
133
+ return fmt .Sprintf ("%t" , v .(bool ))
134
+ default :
135
+ return ""
136
+ }
137
+ }
138
+
139
+ func to_double (v interface {}) float64 {
140
+ switch v .(type ) {
141
+ case string :
142
+ f , _ := strconv .ParseFloat (v .(string ), 64 )
143
+ return f
144
+ case float64 :
145
+ return v .(float64 )
146
+ default :
147
+ return 0
148
+ }
149
+ }
150
+
151
+ func to_integer (v interface {}) int {
152
+ switch v .(type ) {
153
+ case string :
154
+ i , _ := strconv .Atoi (v .(string ))
155
+ return i
156
+ case float64 :
157
+ return int (v .(float64 ))
158
+ case bool :
159
+ if v .(bool ) {
160
+ return 1
161
+ }
162
+ return 0
163
+ default :
164
+ return 0
165
+ }
166
+ }
You can’t perform that action at this time.
0 commit comments