-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtag.go
774 lines (657 loc) · 19 KB
/
tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
package trygo
import (
"errors"
"fmt"
"reflect"
"regexp"
"strconv"
"strings"
)
//`field:"name,limit:20,scope:[1 2 3],default:1,require,pattern:regex"`
//key: is tag item name, value: indicates whether there is value
var supportedTagitems = map[string]bool{
"limit": true,
"scope": true,
"default": true,
"require": false,
"pattern": true,
"layout": true, //time format
}
type Taginfos map[string]*tagInfo
func (this Taginfos) Get(name string) *tagInfo {
return this[name]
}
func (this Taginfos) Set(name string, taginfo *tagInfo) {
this[name] = taginfo
}
func (this Taginfos) Adds(taginfos Taginfos) {
for k, v := range taginfos {
this[k] = v
}
}
func (this Taginfos) Parse(kind reflect.Kind, tag string) {
if tagInfo := parseOneTag(kind, tag); tagInfo != nil {
this.Set(tagInfo.Name, tagInfo)
}
}
func (this Taginfos) ParseStruct(name string, structType reflect.Type, formDomainModel ...bool) {
parseTag(name, structType, "", len(formDomainModel) > 0 && formDomainModel[0], this)
//this.Adds(parseStructTag(name, structType, formDomainModel...))
}
func (this Taginfos) ParseTags(names map[string]reflect.Type, formDomainModel bool, tags ...string) {
this.Adds(parseTags(names, tags, formDomainModel))
}
//`field:"name,limit:20,scope:[1 2 3],default:1,require,pattern:regex"`
type tagInfo struct {
Name string //tag name
TypeKind reflect.Kind //type kind value
Limit limitTag
Require bool
Scope scopeTag
Default defaultTag
Pattern patternTag
Layout layoutTag
}
func (this *tagInfo) String() string {
return fmt.Sprintf("name:%v(%v) (limit:%v, require:%v, scope:%v, default:%v, pattern:%v)", this.Name, this.TypeKind.String(), this.Limit, this.Require, this.Scope, this.Default, this.Pattern)
}
//v - 可以是string类型的请求参数
//dest[0] - 如果提供此参数,将会在dest[0]中返回值,dest[0]原数据类型必须与tagInfo.Type类型一致
func (this *tagInfo) Check(v interface{}, dest ...interface{}) error {
rval := reflect.Indirect(reflect.ValueOf(v))
rvalType := rval.Type()
rvalTypeKind := rvalType.Kind()
tagTypeKind := this.TypeKind
var valLen int
var strval string
if rvalType.Kind() == reflect.String {
strval = rval.String()
valLen = len(strval)
} else {
strval = fmt.Sprint(v)
valLen = len(strval)
}
//Logger.Debug("v:%v", v)
//Logger.Debug("tagInfo:%v", this.String())
//Logger.Debug("strval:%v", strval)
//Logger.Debug("valLen:%v", valLen)
//Logger.Debug("strval:%v", strval)
var destValue reflect.Value
var destTypeKind reflect.Kind
if len(dest) > 0 {
if destPtr, ok := dest[0].(*reflect.Value); ok {
destValue = *destPtr
} else {
destValue = reflect.ValueOf(dest[0])
if destValue.Kind() != reflect.Ptr {
return errors.New("dest is not pointer type")
}
destValue = destValue.Elem()
}
destTypeKind = destValue.Kind()
}
if valLen == 0 {
//check require
if this.Require {
return errors.New("tag require: value is empty, tag:" + this.Name + "(" + this.TypeKind.String() + ")")
} else if this.Default.Exist {
if len(dest) > 0 {
destValue.Set(this.Default.Value)
}
}
return nil
}
//check length limit
if this.Limit.Exist && this.Limit.Value > 0 && valLen > this.Limit.Value {
return errors.New(fmt.Sprintf("tag limit: value is too long, limit:%v, tag:%v(%v)", this.Limit.Value, this.Name, this.TypeKind.String()))
}
//check pattern
if this.Pattern.Exist {
if !this.Pattern.Regexp.MatchString(strval) {
return errors.New(fmt.Sprintf("tag pattern: pattern match fail!, pattern:%v, tag:%v(%v)", this.Pattern.Regexp.String(), this.Name, this.TypeKind.String()))
}
}
//time layouts
var layouts []string
if timeType == destValue.Type() {
if this.Layout.Exist {
layouts = this.Layout.Terms
}
}
var val interface{}
if len(dest) > 0 {
if rvalTypeKind != destTypeKind {
var err error
_, err = parseValue(strval, destTypeKind, &destValue, layouts...)
if err != nil {
return err
}
val = destValue.Interface() //rval.Interface()
} else {
destValue.Set(rval)
val = v
}
}
if val == nil {
if rvalTypeKind != tagTypeKind {
value, err := parseValue(strval, tagTypeKind, nil)
if err != nil {
return err
}
val = value.Interface()
} else {
val = v
}
}
if this.Scope.Exist && !this.Scope.Items.check(val) {
return errors.New(fmt.Sprintf("tag scope: value is not in scope:[%v], tag:%v(%v)", this.Scope.String(), this.Name, this.TypeKind.String()))
}
return nil
}
type tagItem struct {
Exist bool
}
type limitTag struct {
tagItem
Value int
}
type scopeTag struct {
tagItem
Items scopeItems
expr string
}
func (this scopeTag) String() string {
return this.expr
}
type defaultTag struct {
tagItem
Value reflect.Value
}
type patternTag struct {
tagItem
Regexp *regexp.Regexp
}
type layoutTag struct {
tagItem
Terms []string
}
//pnames key is parmeter name, value is parmeter type
func parseTags(pnametypes map[string]reflect.Type, tags []string, formDomainModel bool) (formatedTags Taginfos) {
if len(pnametypes) == 0 {
return
}
pnames := make(map[string]reflect.Type)
for k, v := range pnametypes {
pnames[k] = v
}
formatedTags = make(Taginfos)
for _, tag := range tags {
name, tag := pretreatTag(tag)
if typ, ok := pnames[name]; ok {
parseTag(name, typ, tag, formDomainModel, formatedTags)
delete(pnames, name)
}
}
for name, typ := range pnames {
parseTag(name, typ, "", formDomainModel, formatedTags)
}
return
}
func pretreatTag(tag string) (name, rettag string) {
pair := strings.SplitN(tag, ":\"", 2)
if len(pair) > 1 {
tag = pair[1]
if tag[len(tag)-1] == '"' {
tag = tag[0 : len(tag)-1]
}
}
pair = strings.SplitN(tag, ",", 2)
return strings.TrimSpace(pair[0]), strings.TrimSpace(tag)
}
//分析tag信息
//typ - 属性类型
//tag - 属性tag信息, `:"name,limit:10,scope:[One Two Three],default:Two,require"`
func parseOneTag(kind reflect.Kind, tag string) *tagInfo {
stag := tag
_, tag = pretreatTag(tag)
if tag == "" {
panic("tag is empty, tag:" + stag)
}
//kind := typ.Kind()
switch kind {
case reflect.Slice:
panic("ssss: the slice type is not supported, @see ParseStructTag()")
case reflect.Struct:
panic("ssss: the struct type is not supported, @see ParseStructTag()")
}
if taginfo := parseTagItems(kind, tag); taginfo != nil {
return taginfo
} else {
panic("parse fail, tag:" + stag)
}
return nil
}
//分析tag信息,如果是结构类型,将自动分析结构tag的field字段属性
//name - 属性名
//typ - 属性类型
//tag - 属性tag信息
//formDomainModel[0] @see config.FormDomainModel
//@return taginfos - 在taginfos中返回格式化后的tag信息
//func parseStructTag(name string, structType reflect.Type, formDomainModel ...bool) (taginfos Taginfos) {
// taginfos = make(Taginfos)
// parseTag(name, structType, "", len(formDomainModel) > 0 && formDomainModel[0], taginfos)
// return
//}
const inputTagname = "param"
//var timeType = reflect.TypeOf(time.Now())
func parseTag(pname string, ptype reflect.Type, tag string, formDomainModel bool, formatedTags Taginfos) {
kind := ptype.Kind()
if kind == reflect.Struct && timeType != ptype {
for i := 0; i < ptype.NumField(); i++ {
stag := tag
f := ptype.Field(i)
var attrName string
if f.Anonymous {
attrName = pname
} else {
paramTag := strings.TrimSpace(f.Tag.Get(inputTagname))
if paramTag == "-" {
continue
}
if paramTag != "" {
stag = paramTag
}
paramTags := strings.SplitN(paramTag, ",", 2)
if len(paramTag) > 0 {
attrName = strings.TrimSpace(paramTags[0])
if attrName == "-" {
continue
}
}
if len(attrName) == 0 {
attrName = strings.ToLower(f.Name[0:1]) + f.Name[1:]
}
if formDomainModel && pname != "" {
attrName = pname + "." + attrName
}
}
parseTag(attrName, f.Type, stag, formDomainModel, formatedTags)
}
} else if kind == reflect.Slice {
parseTag(pname, ptype.Elem(), tag, formDomainModel, formatedTags)
} else {
if len(tag) > 0 {
if taginfo := parseTagItems(kind, tag); taginfo != nil {
taginfo.Name = pname
formatedTags[pname] = taginfo
}
}
}
}
func parseTotagitemmap(tag string) (string, map[string]string) {
items := strings.Split(tag, ",")
if len(items) == 0 {
panic("tag is empty or format error, tag:" + tag)
}
tagitemmap := make(map[string]string)
for _, item := range items[1:] {
pair := strings.SplitN(item, ":", 2)
name := strings.TrimSpace(pair[0])
hasval, ok := supportedTagitems[name]
if !ok {
panic("tag item is not supported, item:" + name + ", tag:" + tag)
}
if hasval && (len(pair) < 2 || pair[1] == "") {
panic("tag item (" + name + ") must have value, tag:" + tag)
}
if len(pair) > 1 {
tagitemmap[name] = pair[1]
} else {
tagitemmap[name] = ""
}
}
return strings.TrimSpace(items[0]), tagitemmap
}
func parseTagItems(kind reflect.Kind, tag string) *tagInfo {
name, tagitemmap := parseTotagitemmap(tag)
if name == "" {
panic("tag name is empty, tag:" + tag)
}
tagInfo := &tagInfo{Name: name}
if limit, ok := tagitemmap["limit"]; ok {
tagInfo.Limit.Value = parseInt(limit)
tagInfo.Limit.Exist = true
}
if _, ok := tagitemmap["require"]; ok {
tagInfo.Require = true
}
if scope, ok := tagitemmap["scope"]; ok {
scope = strings.TrimSpace(scope)
scope = strings.Trim(scope, "[]")
tagInfo.Scope.Items = parseScopeTag(strings.Split(scope, " "), kind)
tagInfo.Scope.Exist = true
tagInfo.Scope.expr = scope
}
if pattern, ok := tagitemmap["pattern"]; ok {
var err error
tagInfo.Pattern.Regexp, err = regexp.Compile(pattern)
if err != nil {
panic(err)
}
tagInfo.Pattern.Exist = true
}
if def, ok := tagitemmap["default"]; ok {
defvalue, err := parseValue(def, kind, nil) //tagInfo.Default.Value, err = parseValue(def, kind)
if err != nil {
panic(err)
}
tagInfo.Default.Value = *defvalue
tagInfo.Default.Exist = true
if tagInfo.Scope.Exist && !tagInfo.Scope.Items.check(tagInfo.Default.Value.Interface()) {
panic(fmt.Sprintf("default:%v is not in scope:%s", tagInfo.Default.Value, tagInfo.Scope.expr))
}
if tagInfo.Pattern.Exist && !tagInfo.Pattern.Regexp.MatchString(def) {
panic(fmt.Sprintf("default:%s cannot match pattern:%s", def, tagInfo.Pattern.Regexp.String()))
}
}
if layout, ok := tagitemmap["layout"]; ok {
tagInfo.Layout.Terms = strings.Split(layout, "|")
tagInfo.Layout.Exist = true
}
tagInfo.TypeKind = kind
return tagInfo
}
//func parseTagItems_old(typ reflect.Type, tag string) *tagInfo {
// items := strings.Split(tag, ",")
// if len(items) == 0 {
// panic("tag is empty or format error, tag:" + tag)
// }
// var err error
// tagInfo := &tagInfo{}
// if limitstr, ok := findTag("limit:", items); ok {
// limitstr = strings.TrimLeftFunc(limitstr, unicode.IsSpace)
// tagInfo.Limit.Value = parseInt(limitstr[6:])
// tagInfo.Limit.Exist = true
// }
// if _, ok := findTag("require", items); ok {
// tagInfo.Require = true
// }
// if scopestr, ok := findTag("scope:", items); ok {
// scopestr = strings.TrimLeftFunc(scopestr, unicode.IsSpace)
// scopestr = strings.Trim(scopestr[6:], "[]")
// scopes := strings.Split(scopestr, " ")
// tagInfo.Scope.Items = parseScopeTag(scopes, typ)
// tagInfo.Scope.Exist = true
// tagInfo.Scope.expr = scopestr
// }
// if patternstr, ok := findTag("pattern:", items); ok {
// patternstr = strings.TrimLeftFunc(patternstr, unicode.IsSpace)
// tagInfo.Pattern.Regexp, err = regexp.Compile(patternstr[8:])
// tagInfo.Pattern.Exist = true
// }
// if defstr, ok := findTag("default:", items); ok {
// defstr = strings.TrimLeftFunc(defstr, unicode.IsSpace)
// defstr = defstr[8:]
// tagInfo.Default.Value, err = parseValue(defstr, typ)
// tagInfo.Default.Exist = true
// if tagInfo.Scope.Exist && !tagInfo.Scope.Items.check(tagInfo.Default.Value.Interface()) {
// panic(fmt.Sprintf("default:%v is not in scope:%s", tagInfo.Default.Value, tagInfo.Scope.expr))
// }
// if tagInfo.Pattern.Exist && !tagInfo.Pattern.Regexp.MatchString(defstr) {
// panic(fmt.Sprintf("default:%s cannot match pattern:%s", defstr, tagInfo.Pattern.Regexp.String()))
// }
// }
// if err != nil {
// panic(err)
// }
// tagInfo.Type = typ
// return tagInfo
//}
func parseScopeTag(scopes []string, kind reflect.Kind) scopeItems {
var items []scopeItem
var err error
switch kind {
case reflect.String:
items = parseStringScope(scopes)
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
items, err = parseIntScope(scopes)
if err != nil {
panic(err)
}
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
items, err = parseUintScope(scopes)
if err != nil {
panic(err)
}
case reflect.Float32, reflect.Float64:
items, err = parseFloatScope(scopes)
if err != nil {
panic(err)
}
// case reflect.Slice:
// sliceType := typ.Elem()
// if reflect.Struct == sliceType.Kind() {
// err = errors.New("the parameter type(" + sliceType.String() + ") is not supported")
// } else {
// items = parseScopeTag(scopes, sliceType)
// }
default:
panic("the type(" + kind.String() + ") parameter scope tag is not supported")
}
return items
}
func findTag(name string, items []string) (string, bool) {
for _, v := range items {
if strings.Contains(v, name) {
return v, true
}
}
return "", false
}
func parseInt(s string) int {
v, err := strconv.Atoi(s)
if err != nil {
panic(err)
}
return v
}
const scopeDataTypeEqual = 1
const scopeDataTypeLessthan = 2
const scopeDataTypeGreaterthan = 3
const scopeDataTypeBetween = 4
//scope tag
//[1 2 3] or [1~100] or [0~] or [~0] or [100~] or [~100] or [~-100 -20~-10 -1 0 1 2 3 10~20 100~]
func parseScope(scope []string,
parseData func(sv string) (interface{}, error),
buildScopeItem func(typ int8, v ...interface{}) scopeItem) ([]scopeItem, error) {
items := make([]scopeItem, 0, len(scope))
for _, s := range scope {
if len(s) == 0 {
continue
}
parts := strings.SplitN(s, "~", 2)
if len(parts) == 1 {
v, err := parseData(parts[0])
if err != nil {
return nil, err
}
items = append(items, buildScopeItem(scopeDataTypeEqual, v))
} else { //if len(parts) == 2 {
if len(parts[0]) == 0 {
v, err := parseData(parts[1])
if err != nil {
return nil, err
}
items = append(items, buildScopeItem(scopeDataTypeLessthan, v))
} else if len(parts[1]) == 0 {
v, err := parseData(parts[0])
if err != nil {
return nil, err
}
items = append(items, buildScopeItem(scopeDataTypeGreaterthan, v))
} else { //len(parts[0]) > 0 && len(parts[1]) > 0
start, err := parseData(parts[0])
if err != nil {
return nil, err
}
end, err := parseData(parts[1])
if err != nil {
return nil, err
}
items = append(items, buildScopeItem(scopeDataTypeBetween, start, end))
}
}
}
return items, nil
}
func parseIntScope(scope []string) ([]scopeItem, error) {
return parseScope(scope, func(sv string) (interface{}, error) {
v, err := strconv.ParseInt(sv, 10, 64)
if err != nil {
return nil, err
}
return v, nil
}, func(typ int8, v ...interface{}) scopeItem {
switch typ {
case scopeDataTypeEqual:
return intEqualScopeItem(v[0].(int64))
case scopeDataTypeLessthan:
return intLessthanScopeItem(v[0].(int64))
case scopeDataTypeGreaterthan:
return intGreaterthanScopeItem(v[0].(int64))
case scopeDataTypeBetween:
return intBetweenScopeItem{v[0].(int64), v[1].(int64)}
}
panic("type is unsupported")
})
}
func parseUintScope(scope []string) ([]scopeItem, error) {
return parseScope(scope, func(sv string) (interface{}, error) {
v, err := strconv.ParseUint(sv, 10, 64)
if err != nil {
return nil, err
}
return v, nil
}, func(typ int8, v ...interface{}) scopeItem {
switch typ {
case scopeDataTypeEqual:
return uintEqualScopeItem(v[0].(uint64))
case scopeDataTypeLessthan:
return uintLessthanScopeItem(v[0].(uint64))
case scopeDataTypeGreaterthan:
return uintGreaterthanScopeItem(v[0].(uint64))
case scopeDataTypeBetween:
return uintBetweenScopeItem{v[0].(uint64), v[1].(uint64)}
}
panic("type is unsupported")
})
}
func parseFloatScope(scope []string) ([]scopeItem, error) {
return parseScope(scope, func(sv string) (interface{}, error) {
v, err := strconv.ParseFloat(sv, 64)
if err != nil {
return nil, err
}
return v, nil
}, func(typ int8, v ...interface{}) scopeItem {
switch typ {
case scopeDataTypeEqual:
return floatEqualScopeItem(v[0].(float64))
case scopeDataTypeLessthan:
return floatLessthanScopeItem(v[0].(float64))
case scopeDataTypeGreaterthan:
return floatGreaterthanScopeItem(v[0].(float64))
case scopeDataTypeBetween:
return floatBetweenScopeItem{v[0].(float64), v[1].(float64)}
}
panic("type is unsupported")
})
}
func parseStringScope(scope []string) []scopeItem {
return []scopeItem{stringScopeItems(scope)}
}
type scopeItem interface {
check(v interface{}) bool
}
type scopeItems []scopeItem
func (this scopeItems) check(v interface{}) bool {
for _, item := range []scopeItem(this) {
if item.check(v) {
return true
}
}
return false
}
//string
type stringScopeItems []string
func (this stringScopeItems) check(v interface{}) bool {
for _, s := range []string(this) {
if s == v.(string) {
return true
}
}
return false
}
//int
type intEqualScopeItem int64
func (this intEqualScopeItem) check(v interface{}) bool {
return int64(this) == toInt64(v)
}
type intBetweenScopeItem struct {
Start int64
End int64
}
func (this intBetweenScopeItem) check(v interface{}) bool {
vi64 := toInt64(v) //reflect.ValueOf(v).Int()
return vi64 >= this.Start && vi64 <= this.End
}
type intLessthanScopeItem int64
func (this intLessthanScopeItem) check(v interface{}) bool {
return toInt64(v) <= int64(this)
}
type intGreaterthanScopeItem int64
func (this intGreaterthanScopeItem) check(v interface{}) bool {
return toInt64(v) >= int64(this)
}
//uint
type uintEqualScopeItem uint64
func (this uintEqualScopeItem) check(v interface{}) bool {
return uint64(this) == toUint64(v) //reflect.ValueOf(v).Uint()
}
type uintBetweenScopeItem struct {
Start uint64
End uint64
}
func (this uintBetweenScopeItem) check(v interface{}) bool {
vu64 := toUint64(v) //reflect.ValueOf(v).Uint()
return vu64 >= this.Start && vu64 <= this.End
}
type uintLessthanScopeItem uint64
func (this uintLessthanScopeItem) check(v interface{}) bool {
return toUint64(v) <= uint64(this)
}
type uintGreaterthanScopeItem uint64
func (this uintGreaterthanScopeItem) check(v interface{}) bool {
return toUint64(v) >= uint64(this)
}
//float
type floatEqualScopeItem float64
func (this floatEqualScopeItem) check(v interface{}) bool {
return float64(this) == toFloat64(v) //reflect.ValueOf(v).Float()
}
type floatBetweenScopeItem struct {
Start float64
End float64
}
func (this floatBetweenScopeItem) check(v interface{}) bool {
vf64 := toFloat64(v) //reflect.ValueOf(v).Float()
return vf64 >= this.Start && vf64 <= this.End
}
type floatLessthanScopeItem float64
func (this floatLessthanScopeItem) check(v interface{}) bool {
return toFloat64(v) <= float64(this)
}
type floatGreaterthanScopeItem float64
func (this floatGreaterthanScopeItem) check(v interface{}) bool {
return toFloat64(v) >= float64(this)
}