diff --git a/structs.go b/structs.go index 7ac8836..6cc59e0 100644 --- a/structs.go +++ b/structs.go @@ -74,6 +74,15 @@ func New(s interface{}) *Struct { // fields will be neglected. func (s *Struct) Map() 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() @@ -124,8 +133,6 @@ func (s *Struct) Map() map[string]interface{} { out[name] = finalVal } - - return out } // 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() } +// 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 // Struct types Values() method. It panics if s's kind is not struct. func Values(s interface{}) []interface{} {