Track if the target was created as new during reset

v2
Nikita Tokarchuk 4 years ago
parent 1bfa6c3a21
commit 0bc4e62d80
No known key found for this signature in database
GPG Key ID: DBFD964471BAE65C
  1. 6
      mongox/base/reset.go

@ -6,7 +6,7 @@ import (
)
// Reset function creates new zero object for the target pointer
func Reset(target interface{}) {
func Reset(target interface{}) (created bool) {
type resetter interface {
Reset()
@ -15,7 +15,7 @@ func Reset(target interface{}) {
resettable, canReset := target.(resetter)
if canReset {
resettable.Reset()
return
return false
}
v := reflect.ValueOf(target)
@ -27,4 +27,6 @@ func Reset(target interface{}) {
zero := reflect.Zero(t)
v.Elem().Set(zero)
return true
}

Loading…
Cancel
Save