utils

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCaseToUnderscore added in v1.0.4

func CamelCaseToUnderscore(name string) string

CamelCaseToUnderscore converts CamelCase to under_score style.

Copied from: https://gist.github.com/zxh/cee082053aa9674812e8cd4387088301

func CanBool

func CanBool(v reflect.Value) bool

CanBool returns true if reflect value is of type bool.

func CanBytes

func CanBytes(v reflect.Value) bool

CanBytes returns true if reflect value is of type []byte.

NOTE: []byte == []uint8

func CanComplex

func CanComplex(v reflect.Value) bool

CanComplex returns true if reflect value is of type float.

func CanDuration

func CanDuration(v reflect.Value) bool

CanDuration returns true if reflect value is of type time.Duration, else returns false.

NOTE: time.Duration <=> int64

func CanError

func CanError(v reflect.Value) bool

CanError returns true if reflect value implements the error interface.

func CanFloat

func CanFloat(v reflect.Value) bool

CanFloat returns true if reflect value is of type float.

func CanInt

func CanInt(v reflect.Value) bool

CanInt returns true if reflect value is of type int.

func CanInterface

func CanInterface(v reflect.Value) bool

CanInterface reports whether reflect Interface can be used on reflect value without panicking.

func CanMap

func CanMap(v reflect.Value) bool

CanMap reports whether reflect Map can be used on reflect value without panicking.

func CanNil

func CanNil(v reflect.Value) bool

CanNil returns true if reflect value represents a type that can be set to nil, else returns false.

func CanPtr

func CanPtr(v reflect.Value) bool

CanPtr returns true if reflect value represents a pointer, else returns false.

func CanSlice

func CanSlice(v reflect.Value) bool

CanSlice reports whether reflect Slice can be used on reflect value without panicking.

func CanString

func CanString(v reflect.Value) bool

CanString returns true if reflect value is of type string.

func CanStruct

func CanStruct(v reflect.Value) bool

CanStruct returns true if reflect value represents a nested struct, else returns false.

func CanTime

func CanTime(v reflect.Value) bool

CanTime returns true if reflect value is of type time.Time, else returns false.

func CanUint

func CanUint(v reflect.Value) bool

CanUint returns true if reflect value is of type uint.

func Duration

func Duration(v reflect.Value) (d time.Duration)

Duration returns time.Duration reflect value, else returns zero value.

func Error

func Error(v reflect.Value) error

Error returns the error reflect value, else returns nil.

func Kinds

func Kinds(kinds ...reflect.Kind) string

Kinds returns a comma separated string from list of reflect.Kind's.

func Preset

func Preset(v reflect.Value) reflect.Value

Preset returns concrete value of v in a way that it is ready to be set. If v is a pointer to another type, then it returns the concrete value that the pointer points to. In the case that the pointer is nil (not pointing to anything yet), Preset first has to create zero-value of the type and change the value of the pointer from nil to the address of that zero-value. Then it can returns the concrete value that the pointer points to as well.

Makes sure no pointers points to something concrete, instead of nil.

func StructValueElem

func StructValueElem(v reflect.Value, t reflect.Type) (rv reflect.Value, rt reflect.Type, err error)

StructValueElem follows the pointer v and returns the element it points to, for borth reflect value and reflect type, as well as nil error. If v is not a pointer or not a supported pointer, it returns zero-value reflect value and reflect type as well as an error.

func Time

func Time(v reflect.Value) (t time.Time)

Time returns time.Time reflect value, else returns zero value.

func Zero

func Zero(v reflect.Value) reflect.Value

Zero returns the zero-value of reflect value v.

Types

This section is empty.

Jump to

Keyboard shortcuts

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