parent
57fb40693a
commit
dad0a0598b
@ -0,0 +1,27 @@ |
||||
package base |
||||
|
||||
import ( |
||||
"reflect" |
||||
|
||||
"github.com/mainnika/mongox-go-driver/mongox" |
||||
) |
||||
|
||||
// Reset function creates new zero object for the target pointer
|
||||
func Reset(target interface{}) { |
||||
|
||||
resettable, canReset := target.(mongox.Resetter) |
||||
if canReset { |
||||
resettable.Reset() |
||||
return |
||||
} |
||||
|
||||
v := reflect.ValueOf(target) |
||||
if v.Kind() != reflect.Ptr { |
||||
panic("reset target should be a pointer") |
||||
} |
||||
|
||||
t := v.Elem().Type() |
||||
zero := reflect.Zero(t) |
||||
|
||||
v.Elem().Set(zero) |
||||
} |
Loading…
Reference in new issue