Слияние кода завершено, страница обновится автоматически
/*
* Copyright 2018. bigpigeon. All rights reserved.
* Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file.
*/
package toyorm
import (
"reflect"
)
type IgnoreMode int
const (
IgnoreNo = IgnoreMode(0)
IgnoreFalse = IgnoreMode(1 << iota)
IgnoreZeroInt
IgnoreZeroFloat
IgnoreZeroComplex
IgnoreNilString
IgnoreNilPoint
IgnoreZeroLen
IgnoreNullStruct
IgnoreNil = IgnoreNilPoint | IgnoreZeroLen
IgnoreZero = IgnoreFalse | IgnoreZeroInt | IgnoreZeroFloat | IgnoreZeroComplex | IgnoreNilString | IgnoreNilPoint | IgnoreZeroLen | IgnoreNullStruct
)
func (ignoreMode IgnoreMode) Ignore(v reflect.Value) (ignore bool) {
switch v.Kind() {
case reflect.Bool:
ignore = (ignoreMode&IgnoreFalse) != 0 && IsZero(v)
case reflect.Uintptr, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
ignore = (ignoreMode&IgnoreZeroInt) != 0 && IsZero(v)
case reflect.Float32, reflect.Float64:
ignore = (ignoreMode&IgnoreZeroFloat) != 0 && IsZero(v)
case reflect.Complex64, reflect.Complex128:
ignore = (ignoreMode&IgnoreZeroComplex) != 0 && IsZero(v)
case reflect.String:
ignore = (ignoreMode&IgnoreNilString) != 0 && IsZero(v)
case reflect.Ptr, reflect.Interface:
ignore = (ignoreMode&IgnoreNilPoint) != 0 && IsZero(v)
case reflect.Array:
ignore = (ignoreMode&IgnoreZeroLen) != 0 && IsZero(v)
case reflect.Map:
ignore = ((ignoreMode&IgnoreNilPoint) != 0 && v.IsNil()) || ((ignoreMode&IgnoreZeroLen) != 0 && v.Len() == 0)
case reflect.Slice:
ignore = ((ignoreMode&IgnoreNilPoint) != 0 && v.IsNil()) || ((ignoreMode&IgnoreZeroLen) != 0 && v.Len() == 0)
case reflect.Struct:
ignore = (ignoreMode&IgnoreNullStruct) != 0 && IsZero(v)
}
return
}
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )