meta

package
v2.12.2 Latest Latest
Warning

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

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

README

meta

shortcuts for meta programming in go (using reflect)

Build Status

Documentation

see http://godoc.org/github.com/go-on/meta

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FinalType

func FinalType(i interface{}) reflect.Type

func FinalValue

func FinalValue(i interface{}) reflect.Value

func IsZero

func IsZero(v reflect.Value) bool

func SliceArg

func SliceArg(arg interface{}) (out []interface{})

stolen from https://ahmetalpbalkan.com/blog/golang-take-slices-of-any-type-as-input-parameter/

Types

type Field

type Field struct {
	Value  *reflect.Value
	Type   reflect.StructField
	Struct *Struct
}

func (*Field) Set

func (f *Field) Set(v reflect.Value) error

type Pointer

type Pointer struct {
	Value *reflect.Value
}

func PointerByValue

func PointerByValue(v reflect.Value) (*Pointer, error)

func (*Pointer) Assoc

func (p *Pointer) Assoc(targetPtrPtr reflect.Value) error

Assoc associates targetPtrPtr with srcPtr so that targetPtrPtr is a pointer to srcPtr and targetPtr and srcPtr are pointing to the same address

type Struct

type Struct struct {
	Value *reflect.Value
}

func StructByType

func StructByType(t reflect.Type) (*Struct, error)

t must be a of Kind reflect.Struct

func StructByValue

func StructByValue(val reflect.Value) (*Struct, error)

val must be the reflect.Value of a reference to a struct

func (*Struct) Each

func (s *Struct) Each(fn func(field *Field))

func (*Struct) EachTag

func (s *Struct) EachTag(tagKey string, fn func(field *Field, tagVal string))

get every field and its tag for a given tag key, empty tags and tags with value "-" are ignored

func (*Struct) EachTagWithEmpty

func (s *Struct) EachTagWithEmpty(tagKey string, fn func(field *Field, tagVal string))

get every field and its tag for a given tag key, tags with value "-" are ignored

func (*Struct) Field

func (s *Struct) Field(name string) (*Field, error)

func (*Struct) Set

func (s *Struct) Set(val reflect.Value) error

replace the value of the struct, val must be a pointer to a struct

func (*Struct) Tag

func (s *Struct) Tag(field string) (*reflect.StructTag, error)

returns a struct tag for a field

func (*Struct) Tags

func (s *Struct) Tags() (tags map[string]*reflect.StructTag, err error)

returns all struct tags

func (*Struct) ToMap

func (s *Struct) ToMap(tag string) map[string]interface{}

ToMap converts a given struct to a map. If tag is not "", it follows the same semantics as json encoding, but for the given tag. Panics on errors

func (*Struct) ToPtrMap

func (s *Struct) ToPtrMap(tag string) map[string]interface{}

func (*Struct) ToPtrSlice

func (s *Struct) ToPtrSlice(tag string, fields []string) []interface{}

Jump to

Keyboard shortcuts

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