Exemplo n.º 1
0
func greaterThanOrEqual(current interface{}, field interface{}, param interface{}) bool {
	var fieldValue = reflect.ValueOf(field)

	switch fieldValue.Kind() {
	case reflect.String:
		return fieldValue.String() >= param.(string)
	case reflect.Slice, reflect.Array, reflect.Map:
		p := convert.ConvertToInt(param)
		return fieldValue.Len() >= p
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		p := convert.ConvertToInt64(param)
		return fieldValue.Int() >= p
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		p := convert.ConvertToUint(param)
		return fieldValue.Uint() >= p
	case reflect.Float32, reflect.Float64:
		p := convert.ConvertToFloat64(param)
		return fieldValue.Float() >= p
	case reflect.Struct:
		if fieldValue.Type() == reflect.TypeOf(time.Time{}) {
			var t1 = field.(time.Time).Unix()
			var t2 = convert.ConvertToInt64(param)
			return t1 >= t2
		}
		return false
	default:
		return false
	}
}
Exemplo n.º 2
0
func length(current interface{}, field interface{}, param interface{}) bool {
	var fieldValue = reflect.ValueOf(field)

	switch fieldValue.Kind() {
	case reflect.String:
		l := convert.ConvertToInt(param)
		return utf8.RuneCountInString(fieldValue.String()) == l
	case reflect.Slice, reflect.Array, reflect.Map:
		l := convert.ConvertToInt(param)
		return fieldValue.Len() == l
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		l := convert.ConvertToInt64(param)
		return fieldValue.Int() == l
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
		l := convert.ConvertToUint(param)
		return fieldValue.Uint() == l
	case reflect.Float32, reflect.Float64:
		l := convert.ConvertToFloat64(param)
		return fieldValue.Float() == l
	default:
		return false
	}
}
Exemplo n.º 3
0
func (this *Context) GetInt(key string, defaultValue int) int {
	var value = this.GetValue(key, defaultValue)
	return convert.ConvertToInt(value)
}
Exemplo n.º 4
0
//获取数值
func (this *Context) GetIntWithContext(contextName, key string, defaultValue int) int {
	var value, _ = this.GetValueWithContext(contextName, key, defaultValue)
	return convert.ConvertToInt(value)
}