structs

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 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 is the name of struct attribute of the struct.
	AttrName string

	// ColumnName is the name of the database column described by the ksql tag.
	ColumnName string

	// Index indexes the position of this attribute on the struct.
	// This field is meant to be used together with the
	// `reflect.Value.Field()` and `reflect.Type.Field()` methods.
	Index int

	// Valid will only be set to false if the instance
	// of this field was not initialized, i.e.
	// it denotes the zero value of a FieldInfo.
	//
	// The zero value of this struct is used by the `ByIndex()` and `ByName()`
	// to represent a field not found or a field with no `ksql` tag.
	Valid bool

	// Modifier contains the AttrModifier associated with this field.
	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

	// Fields is a public slice useful for efficiently iterating over the struct fields
	//
	// This slice should be treated as a constant, not adding nor removing items from it.
	Fields []*FieldInfo
	// 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 returns the number of fields on the original struct.

Note that some of these fields might not have `ksql` tags, meaning that fetching these fields `ByIndex()` or `ByName()` would return a zero value.

Jump to

Keyboard shortcuts

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