reflectutil

package
v5.0.0-preview1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Only

func Only(data any, fields ...string) map[string]any

Only extracts the requested field from the given map[string] or structure and returns a map[string]any containing only those values.

For example:

 type Model struct {
   Field string
   Num   int
   Slice []float64
 }
 model := Model{
	  Field: "value",
	  Num:   42,
	  Slice: []float64{3, 6, 9},
 }
 res := reflectutil.Only(model, "Field", "Slice")

Result:

 map[string]any{
	  "Field": "value",
	  "Slice": []float64{3, 6, 9},
 }

In case of conflicting fields (if a promoted field has the same name as a parent's struct field), the higher level field is kept.

Types

This section is empty.

Jump to

Keyboard shortcuts

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