structs

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAsSliceOfStructs

func DecodeAsSliceOfStructs(slice reflect.Type) (
	structType reflect.Type,
	isSliceOfPtrs bool,
	err error,
)

DecodeAsSliceOfStructs makes several checks while decoding an input type and returns useful information so that it is easier to manipulate the original slice later.

func ParseInputFunc

func ParseInputFunc(fn interface{}) (reflect.Type, error)

ParseInputFunc is used exclusively for parsing the ForEachChunk function used on the QueryChunks method.

func StructToMap

func StructToMap(obj interface{}) (map[string]interface{}, error)

StructToMap converts any struct type to a map based on the tag named `ksql`, i.e. `ksql:"map_key_name"`

Valid pointers are dereferenced and copied to the map, null pointers are ignored.

This function is efficient in the fact that it caches the slower steps of the reflection required to perform this task.

Types

type FieldInfo

type FieldInfo struct {
	AttrName   string
	ColumnName string
	Index      int
	Valid      bool
	Modifier   ksqlmodifiers.AttrModifier
}

FieldInfo contains reflection and tags information regarding a specific field of a struct.

type PtrConverter

type PtrConverter struct {
	BaseType  reflect.Type
	BaseValue reflect.Value
	ElemType  reflect.Type
	ElemValue reflect.Value
}

PtrConverter was created to make it easier to handle conversion between ptr and non ptr types, e.g.:

- *type to *type - type to *type - *type to type - type to type

func NewPtrConverter

func NewPtrConverter(v interface{}) PtrConverter

NewPtrConverter instantiates a PtrConverter from an empty interface.

The input argument can be of any type, but if it is a pointer then its Elem() will be used as source value for the PtrConverter.Convert() method.

func (PtrConverter) Convert

func (p PtrConverter) Convert(destType reflect.Type) (reflect.Value, error)

Convert attempts to convert the ElemValue to the destType received as argument and then returns the converted reflect.Value or an error

type StructInfo

type StructInfo struct {
	IsNestedStruct bool
	// contains filtered or unexported fields
}

StructInfo stores metainformation of the struct parser in order to help the ksql library to work efectively and efficiently with reflection.

func GetTagInfo

func GetTagInfo(key reflect.Type) (StructInfo, error)

GetTagInfo efficiently returns the type information using a global private cache

In the future we might move this cache inside a struct, but for now this accessor is the one we are using

func (StructInfo) ByIndex

func (s StructInfo) ByIndex(idx int) *FieldInfo

ByIndex returns either the *FieldInfo of a valid empty struct with Valid set to false

func (StructInfo) ByName

func (s StructInfo) ByName(name string) *FieldInfo

ByName returns either the *FieldInfo of a valid empty struct with Valid set to false

func (StructInfo) NumFields

func (s StructInfo) NumFields() int

NumFields ...

Jump to

Keyboard shortcuts

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