starstruct
Explore the following sections to learn more:
starstruct
import "github.com/gemini-oss/rego/pkg/common/starstruct"
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
func DerefPointers
func DerefPointers(val reflect.Value) (reflect.Value, error)
DerefPointers takes a reflect.Value and recursively dereferences it if it’s a pointer.
func FlattenNestedStructs
func FlattenNestedStructs(item interface{}, prefix string, fieldMap *map[string]string) error
FlattenNestedStructs recursively flattens a struct (and its nested fields) into a map. The keys are generated using the provided prefix.
func FlattenStructFields
func FlattenStructFields(item interface{}, opts ...Option) ([][]string, error)
FlattenStructFields recursively flattens a struct and its nested fields into a two-dimensional slice.
func GenerateFieldNames
func GenerateFieldNames(prefix string, val reflect.Value, opts ...Option) (*[]string, error)
GenerateFieldNames recursively generates field names from a struct (or slice/map thereof), dereferencing pointers as needed.
func MergeFields
func MergeFields(baseline, candidate []string) []string
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
func PrettyJSON(data interface{}) (string, error)
* Print a struct as a JSON string
func TableToStructs
func TableToStructs(data [][]string) ([]interface{}, error)
TableToStructs converts a [][]string into a slice of structs, with the first row as headers.
func ToMap
func ToMap(item interface{}, includeZeroValues bool) (map[string]interface{}, error)
ToMap converts a struct (or map) to a map[string]interface{}. If includeZeroValues is false then any field with a zero value is skipped.
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
func WithHeaders(headers *[]string) Option
WithHeaders tells the package to use the provided headers
func WithSort
func WithSort() Option
WithSortFields tells the package to sort the fields of the struct
Generated by gomarkdoc