Documentation
¶
Overview ¶
pkg/common/starstruct/fields.go
pkg/common/starstruct/struct.go
Index ¶
- func DerefPointers(val reflect.Value) (reflect.Value, error)
- func FlattenNestedStructs(item interface{}, prefix string, fieldMap *map[string]string) error
- func FlattenStructFields(item interface{}, opts ...Option) ([][]string, error)
- func GenerateFieldNames(prefix string, val reflect.Value, opts ...Option) (*[]string, error)
- func MergeFields(baseline, candidate []string) []string
- func PrettyJSON(data interface{}) (string, error)
- func TableToStructs(data [][]string) ([]interface{}, error)
- func ToMap(item interface{}, includeZeroValues bool) (map[string]interface{}, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DerefPointers ¶
DerefPointers takes a reflect.Value and recursively dereferences it if it's a pointer.
func FlattenNestedStructs ¶
FlattenNestedStructs recursively flattens a struct (and its nested fields) into a map. The keys are generated using the provided prefix.
func FlattenStructFields ¶
FlattenStructFields recursively flattens a struct and its nested fields into a two-dimensional slice.
func GenerateFieldNames ¶
GenerateFieldNames recursively generates field names from a struct (or slice/map thereof), dereferencing pointers as needed.
func MergeFields ¶
MergeFields merges parent and subfields according to these rules:
- If a baseline field has candidate subfields (numeric or non‑numeric), the baseline field is omitted and the candidate subfields are inserted in its place.
- (When numeric candidate subfields exist, they are sorted by their numeric suffix.)
- If a candidate field does not map to a baseline field but shares a top‑level prefix, insert it after the last baseline field that has that prefix.
- Bare candidate fields (with no dot) are appended at the end if not in baseline.
- No duplicates. Baseline ordering is preserved as the “master” order.
func PrettyJSON ¶
* Print a struct as a JSON string
func TableToStructs ¶
TableToStructs converts a [][]string into a slice of structs, with the first row as headers.
Types ¶
type Option ¶
type Option func(*pkgConfig)
func WithExcludeNil ¶
func WithExcludeNil() Option
WithExcludeNilStructs instructs the package to skip expanding fields in nil pointer-structs.
func WithGenerate ¶
func WithGenerate() Option
WithGenerateFields tells the package to generate fields dynamically
func WithHeaders ¶
WithHeaders tells the package to use the provided headers