Documentation ¶
Index ¶
- type Codec
- type FieldCodec
- type FieldReader
- type FieldWriter
- type Reader
- type Set
- func (s *Set) Add(src interface{}) error
- func (s *Set) AddMust(src interface{})
- func (s *Set) Get(src interface{}) (*Codec, error)
- func (s *Set) NewReader(src interface{}) (*Reader, error)
- func (s *Set) NewWriter(dst interface{}) (*Writer, error)
- func (s *Set) SetValidateFunc(fn func(*Set, *Codec) error)
- type TagCodec
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Codec ¶
type Codec struct { // Type returns the struct's type. Type reflect.Type // Fields returns the struct's field codecs. Fields []*FieldCodec // FieldNames returns the struct's exportable field names. FieldNames []string // Attrs can contain custom attributes of the codec. Attrs map[string]interface{} // Complete is whether the codec is completely processed. // An incomplete codec may be encountered when walking a recursive struct. Complete bool }
Codec represents a struct and its fields.
type FieldCodec ¶
type FieldCodec struct { // Parent is a reference to the struct the field is in. Parent *Codec // Index is the index of the field in the struct. Index int // Anonymous is whether the field is embedded. Anonymous bool // Name is the name of the field in the struct. Name string // Tag is the codec for the field's tags. Tag *TagCodec // Attrs can contain custom attributes of the field's codec. Attrs map[string]interface{} // Type is the field's type. Type reflect.Type // KeyType is the type of the field's key, if any. KeyType *reflect.Type // ElemType is the type of the field's collection's value type, if any. ElemType *reflect.Type }
FieldCodec represents a struct field.
type FieldReader ¶
type FieldReader struct { *FieldCodec // contains filtered or unexported fields }
FieldReader represents a readable struct field.
func (*FieldReader) Value ¶
func (fld *FieldReader) Value() interface{}
Value returns the field's value.
type FieldWriter ¶
type FieldWriter struct { *FieldReader // contains filtered or unexported fields }
FieldWriter represents a writable field.
func (*FieldWriter) SetValue ¶
func (fld *FieldWriter) SetValue(value interface{}) error
SetValue applies the passed-in value to the field. It returns an error if the field is not writable or the value's type does not match the field's.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader represents a readable struct.
func (*Reader) Fields ¶
func (r *Reader) Fields() []*FieldReader
Fields returns the readable fields of the struct.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a collection of codecs, for a specific tag name.
func (*Set) Add ¶
Add creates a new codec from the passed-in value and adds it to the set. It expects a struct, struct pointer or reflect.Type of a struct.
func (*Set) AddMust ¶
func (s *Set) AddMust(src interface{})
AddMust creates a new codec from the passed-in value and adds it to the set. It panics if an error occurs.
func (*Set) Get ¶
Get returns the according codec for the passed-in value. It returns an error if the value is invalid or no codec was found.
func (*Set) NewReader ¶
NewReader returns a new reader for the passed-in value, expecting a struct or struct pointer. It returns an error if the value is invalid or no matching codec was found.