Add FillMap(s interface{}, out map[string]interface{})
This commit is contained in:
parent
12ff68a6f4
commit
179aa9d3d4
16
structs.go
16
structs.go
@ -74,6 +74,15 @@ func New(s interface{}) *Struct {
|
|||||||
// fields will be neglected.
|
// fields will be neglected.
|
||||||
func (s *Struct) Map() map[string]interface{} {
|
func (s *Struct) Map() map[string]interface{} {
|
||||||
out := make(map[string]interface{})
|
out := make(map[string]interface{})
|
||||||
|
s.FillMap(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillMap is the same as Map. Instead of returning the output, it fills the given input
|
||||||
|
func (s *Struct) FillMap(out map[string]interface{}) {
|
||||||
|
if out == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fields := s.structFields()
|
fields := s.structFields()
|
||||||
|
|
||||||
@ -124,8 +133,6 @@ func (s *Struct) Map() map[string]interface{} {
|
|||||||
|
|
||||||
out[name] = finalVal
|
out[name] = finalVal
|
||||||
}
|
}
|
||||||
|
|
||||||
return out
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Values converts the given s struct's field values to a []interface{}. A
|
// Values converts the given s struct's field values to a []interface{}. A
|
||||||
@ -427,6 +434,11 @@ func Map(s interface{}) map[string]interface{} {
|
|||||||
return New(s).Map()
|
return New(s).Map()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FillMap is the same as Map. Instead of returning the output, it fills the given input
|
||||||
|
func FillMap(s interface{}, out map[string]interface{}) {
|
||||||
|
New(s).FillMap(out)
|
||||||
|
}
|
||||||
|
|
||||||
// Values converts the given struct to a []interface{}. For more info refer to
|
// Values converts the given struct to a []interface{}. For more info refer to
|
||||||
// Struct types Values() method. It panics if s's kind is not struct.
|
// Struct types Values() method. It panics if s's kind is not struct.
|
||||||
func Values(s interface{}) []interface{} {
|
func Values(s interface{}) []interface{} {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user