mirror

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: BSD-3-Clause Imports: 3 Imported by: 0

README

Mirror

Mirror is a small Go package that allows passing struct fields by value with the use of a mirror.Type

var get mirror.Type
var StreetAddress struct {
    Number int
    Street string

    Postcode int
}

//Reflect the value onto the mirror.
get.Reflect(&StreetAddress)

//Inspect fields by struct-value.
get.Field(StreetAddress.Number).Name    //"Number"
get.Field(StreetAddress.Postcode).Name  //"Postcode"
get.Field(StreetAddress.Street).Name    //"Street"

Documentation

Overview

Package mirror implements run-time 'mirror' reflection, allowing struct fields to be passed to functions in a type-safe manner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	reflect.StructField

	Parent int
}

Field of a struct.

type Type

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

Type is a mirrored type used to store a field-mapping.

func (Type) Field

func (t Type) Field(field interface{}) Field

Field returns the value's field, if the value was not initialised with this Type's call to Reflect, Field panics or returns an undefined field.

func (Type) Path

func (t Type) Path(field interface{}) string

Path returns the field's path in Go syntax rooted at the mirrored type, if the value was not initialised with this Type's call to Reflect, Path panics or returns an undefined field.

func (*Type) Reflect

func (t *Type) Reflect(value interface{})

Reflect reflects the fields of the value onto the mirror.

Jump to

Keyboard shortcuts

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