gotypes

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 8 Imported by: 49

Documentation

Index

Constants

View Source
const (
	EMPTYSTR = ""
)

Variables

View Source
var (
	BoolType         = reflect.TypeOf(boolValue)
	IntType          = reflect.TypeOf(intValue)
	Int8Type         = reflect.TypeOf(int8Value)
	Int16Type        = reflect.TypeOf(int16Value)
	Int32Type        = reflect.TypeOf(int32Value)
	Int64Type        = reflect.TypeOf(int64Value)
	UintType         = reflect.TypeOf(uintValue)
	Uint8Type        = reflect.TypeOf(uint8Value)
	Uint16Type       = reflect.TypeOf(uint16Value)
	Uint32Type       = reflect.TypeOf(uint32Value)
	Uint64Type       = reflect.TypeOf(uint64Value)
	Float32Type      = reflect.TypeOf(float32Value)
	Float64Type      = reflect.TypeOf(float64Value)
	StringType       = reflect.TypeOf(stringValue)
	BoolSliceType    = reflect.TypeOf(boolSliceValue)
	IntSliceType     = reflect.TypeOf(intSliceValue)
	Int8SliceType    = reflect.TypeOf(int8SliceValue)
	Int16SliceType   = reflect.TypeOf(int16SliceValue)
	Int32SliceType   = reflect.TypeOf(int32SliceValue)
	Int64SliceType   = reflect.TypeOf(int64SliceValue)
	UintSliceType    = reflect.TypeOf(uintSliceValue)
	Uint8SliceType   = reflect.TypeOf(uint8SliceValue)
	Uint16SliceType  = reflect.TypeOf(uint16SliceValue)
	Uint32SliceType  = reflect.TypeOf(uint32SliceValue)
	Uint64SliceType  = reflect.TypeOf(uint64SliceValue)
	Float32SliceType = reflect.TypeOf(float32SliceValue)
	Float64SliceType = reflect.TypeOf(float64SliceValue)
	StringSliceType  = reflect.TypeOf(stringSliceValue)
	TimeType         = reflect.TypeOf(timeValue)
)
View Source
var (
	ISerializableType = reflect.TypeOf((*ISerializable)(nil)).Elem()

	ErrTypeNotSerializable = errors.New("Type not serializable")
)

Functions

func AppendValue

func AppendValue(value reflect.Value, val string) error

func AppendValues

func AppendValues(value reflect.Value, vals ...string) error

func ConvertSliceElemType

func ConvertSliceElemType(vals interface{}, val interface{}) interface{}

Convert vals to slice of pointer val's element type

This is for the following use cases, not for general type conversion

  • Convert []Interface to []ConcreteType
  • Convert []ConcreateType to []Interface

func DeepCopy

func DeepCopy(v interface{}) interface{}

DeepCopy copies the passed argument recursively

There are a few constraint

  • It cannot handle un-exported fields
  • It cannot handle circular references. Doing so will cause runtime stack overflow panic

func DeepCopyRv

func DeepCopyRv(rv reflect.Value) reflect.Value

func GetInstanceTypeName

func GetInstanceTypeName(instance interface{}) string

func InCollection

func InCollection(obj interface{}, array interface{}) bool

func IsFieldExportable

func IsFieldExportable(fieldName string) bool

func IsNil

func IsNil(val interface{}) bool

func IsSerializable

func IsSerializable(valType reflect.Type) bool

func ParseValue

func ParseValue(val string, tp reflect.Type) (reflect.Value, error)

func RegisterSerializable

func RegisterSerializable(valType reflect.Type, alloc FuncSerializableAllocator)

RegisterSerializable registers an allocator func for the specified serializable type.

This is intended to be used when you have multiple implmenetations of an interface and you want to use only one of them to cover them all. TokenCredential and SSimpleToken is such a case.

func RegisterSerializableTransformer

func RegisterSerializableTransformer(valType reflect.Type, trans FuncSerializableTransformer)

func SetValue

func SetValue(value reflect.Value, valStr string) error

func SliceBaseType

func SliceBaseType(tp reflect.Type) reflect.Type

Types

type DeepCopyFlags

type DeepCopyFlags uintptr

type FuncSerializableAllocator

type FuncSerializableAllocator func() ISerializable

type FuncSerializableTransformer

type FuncSerializableTransformer func(ISerializable) ISerializable

type IDeepCopy

type IDeepCopy interface {
	DeepCopy() interface{}
}

type ISerializable

type ISerializable interface {
	String() string
	// FromString(str string) error
	// Equals(obj ISerializable) bool
	IsZero() bool
}

func NewSerializable

func NewSerializable(objType reflect.Type) (ISerializable, error)

func Transform

func Transform(objType reflect.Type, retVal ISerializable) ISerializable

Jump to

Keyboard shortcuts

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