reflect

package
v0.0.0-...-c4bedde Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

This package provides some punk-rock reflection which is not in the stdlib.

Index

Constants

View Source
const TagName = "cql"

Variables

This section is empty.

Functions

func FieldsAndValues

func FieldsAndValues(val interface{}) ([]string, []interface{}, bool)

FieldsAndValues returns a list field names and a corresponding list of values for the given struct. For details on how the field names are determined please see StructToMap.

func MapToStruct

func MapToStruct(m map[string]interface{}, struc interface{}) error

MapToStruct converts a map to a struct. It is the inverse of the StructToMap function. For details see StructToMap.

func StructFieldMap

func StructFieldMap(structType r.Type, lowercaseFields bool) (map[string]Field, error)

StructFieldMap takes a struct type and extracts the Field info into a map by field name. The "cql" key in the struct field's tag value is the key name. Examples:

// Field appears in the resulting map as key "myName".
Field int `cql:"myName"`

// Field appears in the resulting as key "Field"
Field int

// Field appears in the resulting map as key "myName"
Field int "myName"

If lowercaseFields is set to true, field names are lowercased in the map

func StructToMap

func StructToMap(val interface{}) (map[string]interface{}, bool)

StructToMap converts a struct to map. The object's default key string is the struct field name but can be specified in the struct field's tag value. The "cql" key in the struct field's tag value is the key name. Examples:

// Field appears in the resulting map as key "myName".
Field int `cql:"myName"`

// Field appears in the resulting as key "Field"
Field int

// Field appears in the resulting map as key "myName"
Field int "myName"

Types

type Field

type Field struct {
	// contains filtered or unexported fields
}

Field represents a single field found in a struct.

func (Field) Index

func (f Field) Index() []int

func (Field) Name

func (f Field) Name() string

func (Field) Type

func (f Field) Type() reflect.Type

Jump to

Keyboard shortcuts

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