utils

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 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

Improvement upon default approach, which is:

import "github.com/asaskevich/govalidator"
return govalidator.CamelCaseToUnderscore(f.field.Name)

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

func IndirectType(v reflect.Value) reflect.Type

IndirectType returns the type that v points to. If v is a pointer, IndirectType returns the type v points to. If v is not a pointer, IndirectType returns the type of v.

func Kinds

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

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

func PresetIndirect added in v1.0.6

func PresetIndirect(v reflect.Value) reflect.Value

PresetIndirect returns the value that v points to (like reflect.Indirect). If v is a nil pointer, PresetIndirect returns a zero Value. If v is not a pointer, PresetIndirect returns v.

Unlike in reflect.Indirect, if v was a nil pointer, v does not stay a nil pointer. Now v points to the zero Value returned. Useful when preparing v just before setting its conrete value.

Example:

if v is nil pointer to string, PresetIndirect returns "" and v points to "".

func StringToTime added in v1.0.6

func StringToTime(s string) (t time.Time, err 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