reflecthelper

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2020 License: GPL-3.0 Imports: 3 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 Clone added in v1.0.4

func Clone(val reflect.Value) (res reflect.Value)

Clone clones the current underlying value of val as a reflect.Value. Clone can't clone unexported struct field because it is inaccessible.

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 GetElemKind added in v1.0.6

func GetElemKind(val reflect.Value) (res reflect.Kind)

GetElemKind gets the elem kind from ptr type.

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 GetKind added in v1.0.6

func GetKind(val reflect.Value) (res reflect.Kind)

GetKind gets the kind of the reflect.Value.

func InitNew added in v1.0.4

func InitNew(val reflect.Value) (res reflect.Value)

InitNew initializes a new reflect.Value with reflect.Type of val.

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

func SetReflectZero added in v1.0.3

func SetReflectZero(val reflect.Value)

SetReflectZero sets the val to the reflect.Zero of its type.

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