structs

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SliceSeparator is used to separate slice and map items.
	SliceSeparator = ','

	// MapKeySeparator is used to separate map keys and their value.
	MapKeySeparator = ':'
)

Variables

This section is empty.

Functions

func MarshalValue

func MarshalValue(v interface{}, seps ...rune) (interface{}, error)

MarshalValue converts v into a higher level value or a string as follows:

  • int, int8, int16, int32 -> int64
  • uint, uint8, uint16, uint32 -> uint64
  • float32 -> float64
  • any slice/map/array -> string
  • time.Time, *text/template.Template, *html/template.Template, *regexp.RegExp, *url.URL -> string
  • *net.IPAddr, *net.IPNet -> string
  • encoding.TextMarshaler -> string

The following types are returned as is:

  • bool, time.Duration, float64, int, int64, string, uint, uint64

sliceSep, mapKeySep

func Set

func Set(value reflect.Value, v interface{}, seps ...rune) error

Set assigns v to the value. If v is a string but value is not, then Set attempts to deserialize it using UnmarshalValue().

func UnmarshalValue

func UnmarshalValue(value reflect.Value, s string, seps ...rune) error

UnmarshalValue unmarshals s into value. sliceSep, mapKeySep

Types

type StructField

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

StructField represents a struct field.

func (*StructField) Embedded

func (f *StructField) Embedded() *StructStruct

Embedded returns the embedded struct if the field is embedded.

func (*StructField) Name

func (f *StructField) Name() string

Name returns the field name.

func (*StructField) PtrValue

func (f *StructField) PtrValue() interface{}

PtrValue returns the interface pointer value of the field.

func (*StructField) Set

func (f *StructField) Set(v interface{}, seps ...rune) error

Set assigns the given value to the field. If the value is a string but the field is not, then its value is deserialized using encoding.Unmarshaler or in a best effort way.

func (*StructField) Tag

func (f *StructField) Tag() reflect.StructTag

Tag returns the tags defined on the field.

func (*StructField) Value

func (f *StructField) Value() interface{}

Value returns the interface value of the field.

type StructStruct

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

StructStruct represents a decomposed struct.

func NewStruct

func NewStruct(s interface{}, tagid string) (*StructStruct, error)

NewStruct recursively decomposes the input struct into its fields and embedded structs. Fields tags with "-" will be skipped. Fields tags with a non empty value will be renamed to that value.

The input must be a pointer to a struct.

func (*StructStruct) Call

func (s *StructStruct) Call(m string, args []interface{}) ([]interface{}, bool)

Call invokes the method m on s with arguments args.

It returns the method results and whether is was invoked successfully.

func (*StructStruct) CallUntil

func (s *StructStruct) CallUntil(m string, args []interface{}, until func([]interface{}) bool) ([]interface{}, bool)

CallUntil recursively calls the given method on its StructStruct fields and stops at the first one satisfying the stop condition.

func (*StructStruct) Fields

func (s *StructStruct) Fields() []*StructField

Fields returns all the fields of the parsed struct.

func (*StructStruct) GoString

func (s *StructStruct) GoString() string

GoString is used to debug a StructStruct and returns a full and human readable representation of its elements.

func (*StructStruct) Lookup

func (s *StructStruct) Lookup(path ...string) *StructField

Lookup returns the field for the corresponding path.

func (*StructStruct) Name

func (s *StructStruct) Name() string

Name returns the underlying type name.

func (*StructStruct) String

func (s *StructStruct) String() string

String gives a simple string representation of the StructStruct.

Jump to

Keyboard shortcuts

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