github.com/yandex/pandora@v0.5.32/core/coreutil/ammo.go (about)

     1  package coreutil
     2  
     3  import (
     4  	"reflect"
     5  
     6  	"github.com/yandex/pandora/core"
     7  )
     8  
     9  // ResetReusedAmmo sets to zero any ammo.
    10  // Used by core.Provider implementations that accepts generic type, and need to clean reused ammo
    11  // before fill with fresh data.
    12  func ResetReusedAmmo(ammo core.Ammo) {
    13  	if resettable, ok := ammo.(core.ResettableAmmo); ok {
    14  		resettable.Reset()
    15  		return
    16  	}
    17  	elem := reflect.ValueOf(ammo).Elem()
    18  	elem.Set(reflect.Zero(elem.Type()))
    19  }