1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/bigpigeon-toyorm

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
ignore_mode.go 1.8 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
bigpigeon Отправлено 17.03.2018 08:15 9b3081a
/*
* 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 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/bigpigeon-toyorm.git
git@api.gitlife.ru:oschina-mirror/bigpigeon-toyorm.git
oschina-mirror
bigpigeon-toyorm
bigpigeon-toyorm
master