Documentation
¶
Overview ¶
Package reflectutil provides reflection utilities for analyzing Go code structures.
Overview ¶
The reflectutil package offers helper functions for working with Go's reflection capabilities, particularly for parsing Go struct definitions and extracting type information. This is used by readers that parse ORM model files.
Features ¶
- Struct tag parsing and extraction
- Type information analysis
- Field metadata extraction
- ORM tag interpretation (GORM, Bun, etc.)
Usage ¶
This package is primarily used internally by readers like GORM and Bun to parse Go struct definitions and convert them to database schema models.
// Example: Parse struct tags
tags := reflectutil.ParseStructTags(field)
columnName := tags.Get("db")
Supported ORM Tags ¶
The package understands tag conventions from:
- GORM (gorm tag)
- Bun (bun tag)
- Standard database/sql (db tag)
Purpose ¶
This package enables RelSpec to read existing ORM models and convert them to a unified schema representation for transformation to other formats.
Index ¶
- func CompareValues(a, b interface{}) int
- func DeepEqual(a, b interface{}) bool
- func Deref(v reflect.Value) (reflect.Value, bool)
- func DerefInterface(i interface{}) reflect.Value
- func GetFieldValue(item interface{}, field string) interface{}
- func GetNestedValue(m interface{}, path string) interface{}
- func IsMap(i interface{}) bool
- func IsSliceOrArray(i interface{}) bool
- func MapGet(m interface{}, key interface{}) interface{}
- func MapKeys(i interface{}) []interface{}
- func MapLen(i interface{}) int
- func MapValues(i interface{}) []interface{}
- func SliceIndex(slice interface{}, index int) interface{}
- func SliceLen(i interface{}) int
- func SliceToInterfaces(i interface{}) []interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareValues ¶
func CompareValues(a, b interface{}) int
CompareValues compares two values for sorting Returns -1 if a < b, 0 if a == b, 1 if a > b
func DeepEqual ¶
func DeepEqual(a, b interface{}) bool
DeepEqual performs a deep equality check between two values
func Deref ¶
Deref dereferences pointers until it reaches a non-pointer value Returns the dereferenced value and true if successful, or the original value and false if nil
func DerefInterface ¶
DerefInterface dereferences an interface{} until it reaches a non-pointer value
func GetFieldValue ¶
func GetFieldValue(item interface{}, field string) interface{}
GetFieldValue extracts a field value from a struct, map, or pointer Returns nil if the field doesn't exist or can't be accessed
func GetNestedValue ¶
func GetNestedValue(m interface{}, path string) interface{}
GetNestedValue gets a nested value using dot notation path Example: GetNestedValue(obj, "database.schema.table")
func IsSliceOrArray ¶
func IsSliceOrArray(i interface{}) bool
IsSliceOrArray checks if an interface{} is a slice or array
func MapGet ¶
func MapGet(m interface{}, key interface{}) interface{}
MapGet safely gets a value from a map by key Returns nil if key doesn't exist or not a map
func MapKeys ¶
func MapKeys(i interface{}) []interface{}
MapKeys returns all keys from a map as []interface{} Returns empty slice if not a map
func MapValues ¶
func MapValues(i interface{}) []interface{}
MapValues returns all values from a map as []interface{} Returns empty slice if not a map
func SliceIndex ¶
func SliceIndex(slice interface{}, index int) interface{}
SliceIndex safely gets an element from a slice/array by index Returns nil if index out of bounds or not a slice/array
func SliceLen ¶
func SliceLen(i interface{}) int
SliceLen returns the length of a slice/array, or 0 if not a slice/array
func SliceToInterfaces ¶
func SliceToInterfaces(i interface{}) []interface{}
SliceToInterfaces converts a slice/array to []interface{} Returns empty slice if not a slice/array
Types ¶
This section is empty.