reflects

package
v0.0.0-...-82e7740 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2019 License: MIT Imports: 4 Imported by: 0

README

util-reflects GoDoc

reflect library for Go

Installation

go get gopkg.in/goyy/goyy.v0/util/reflects

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(i interface{}, methodName string, methodArgs ...interface{}) (result []interface{}, err error)

Call calls the function i with the input arguments.

func Field

func Field(i interface{}, fieldName string) (field reflect.Value, err error)

Field returns i's reflect.Value. It error if i's Kind is not Struct or Ptr.

func FieldInterfaces

func FieldInterfaces(v reflect.Value) (map[string]interface{}, error)

FieldInterfaces returns the field - value struct pairs as a map.

func FieldNames

func FieldNames(t reflect.Type, anonymous bool) (names []string, err error)

FieldNames returns the struct fields names list. If anonymous is true that contains the field names anonymous.

func FieldTags

func FieldTags(t reflect.Type, tagKey string) (map[string]string, error)

FieldTags lists the struct tag fields.

func HasAnyType

func HasAnyType(v reflect.Type, types []reflect.Kind) bool

HasAnyType returns true if any type in types are within v.

func HasPtr

func HasPtr(v reflect.Value) bool

HasPtr returns true if i is of type pointer.

func HasSlice

func HasSlice(v reflect.Value) bool

HasSlice returns true if i is of type slice.

func HasString

func HasString(v reflect.Value) bool

HasString returns true if i is of type string.

func HasStruct

func HasStruct(v reflect.Value) bool

HasStruct returns true if i is of type struct.

func Indirect

func Indirect(i interface{}) (v reflect.Value)

Indirect returns the value that i points to. If i is a nil pointer, Indirect returns a zero Value. If i is not a pointer, Indirect returns i.

func Interface

func Interface(i interface{}, fieldName string) (interface{}, error)

Interface returns i's current value as an interface{}. It error if the Value was obtained by accessing unexported struct fields.

func Interfaces

func Interfaces(i interface{}) (map[string]interface{}, error)

Interfaces returns the field - value struct pairs as a map. It error if i's Kind is not Struct or Ptr.

func IsAnyType

func IsAnyType(i interface{}, types []reflect.Kind) bool

IsAnyType returns true if any type in types are within i.

func IsField

func IsField(i interface{}, fieldName string) (bool, error)

IsField checks if i field name is part of a struct. It error if i's Kind is not Struct or Ptr.

func IsPtr

func IsPtr(i interface{}) bool

IsPtr returns true if i is of type pointer.

func IsSlice

func IsSlice(i interface{}) bool

IsSlice returns true if i is of type slice.

func IsString

func IsString(i interface{}) bool

IsString returns true if i is of type string.

func IsStruct

func IsStruct(i interface{}) bool

IsStruct returns true if i is of type struct.

func IsStructOrStructPtr

func IsStructOrStructPtr(i interface{}) bool

IsStructOrStructPtr returns true if i is of type struct or struct pointer.

func IsStructPtr

func IsStructPtr(i interface{}) bool

IsStructPtr returns true if i is of type struct pointer.

func IsTag

func IsTag(i interface{}, fieldName, tagKey string) (bool, error)

IsTag checks if i field tag is part of a struct. It error if i's Kind is not Struct or Ptr.

func Kind

func Kind(i interface{}, fieldName string) (reflect.Kind, error)

Kind returns i's Kind. If i is the zero Value (IsValid returns false), Kind returns Invalid.

func MakeSlice

func MakeSlice(i interface{}, len, cap int) interface{}

MakeSlice creates a new zero-initialized slice value for the specified slice type, length, and capacity.

func Method

func Method(i interface{}, methodName string) (method reflect.Value, err error)

Method returns i's reflect.Value. It error if i's Kind is not Struct or Ptr.

func Names

func Names(i interface{}, anonymous bool) ([]string, error)

Names returns the struct fields names list. It error if i's Kind is not Struct or Ptr. If anonymous is true that contains the field names anonymous.

func Set

func Set(i interface{}, fieldName string, value interface{}) error

Set assigns value to the interface{} i. It error if CanSet returns false. As in Go, value's interface{} must be assignable to i's type.

func StructField

func StructField(i interface{}, fieldName string) (field reflect.StructField, err error)

StructField returns i's reflect.StructField. It error if i's Kind is not Struct or Ptr.

func Tag

func Tag(i interface{}, fieldName, tagKey string) (string, error)

Tag returns the value associated with tagKey in the tag string. If there is no such tagKey in the tag, Get returns the empty string. If the tag does not have the conventional format, the value returned by Get is unspecified.

func Tags

func Tags(i interface{}, tagKey string) (map[string]string, error)

Tags lists the struct tag fields. It error if i's Kind is not Struct or Ptr.

Types

This section is empty.

Jump to

Keyboard shortcuts

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