reflecthelper

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2020 License: GPL-3.0 Imports: 2 Imported by: 0

README

reflecthelper

Reflecthelper is a collection of helper function that works with Reflect in go-lang.

Documentation

Index

Constants

View Source
const (
	ZeroTime0 = "0000-00-00 00:00:00"
	ZeroTime1 = "0001-01-01 00:00:00"
)

List of constants for the zero time.

Variables

This section is empty.

Functions

func GetChildElem

func GetChildElem(v reflect.Value) (res reflect.Value)

GetChildElem gets the child elem if it is a pointer with an element of pointer.

func GetInitElem

func GetInitElem(v reflect.Value) (res reflect.Value)

GetInitElem gets the element of a pointer value. It initialize the element of a pointer value if it is nil.

func IsArrayZero

func IsArrayZero(v reflect.Value) bool

IsArrayZero checks if the array is empty.

func IsInterfaceReflectZero added in v1.0.1

func IsInterfaceReflectZero(val interface{}) (result bool)

IsInterfaceReflectZero checks whether the interface is nil. It also checks if the reflect.Value of val is reflect.Zero of it's type.

func IsReflectZero added in v1.0.1

func IsReflectZero(val reflect.Value) (result bool)

IsReflectZero check if the val of reflect.Value is a reflect.Zero of it's type. This operation is solely based on reflect.Zero, not to check if the actual underlying value is zero. To check if the value of reflect.Value is zero, use IsZero or IsValueZero.

func IsStructZero

func IsStructZero(v reflect.Value) bool

IsStructZero checks if the struct is zero.

func IsTimeZero

func IsTimeZero(t time.Time) bool

IsTimeZero checks if the time is zero.

func IsValueZero

func IsValueZero(v reflect.Value) bool

IsValueZero check the reflect.Value if it is zero based on it's kind.

func IsZero

func IsZero(k interface{}) bool

IsZero returns false if k is nil or has a zero value

Types

type Zeroable

type Zeroable interface {
	IsZero() bool
}

Zeroable is a contract to specifies the Zero attribute of a custom type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL