36 lines
896 B
Go
36 lines
896 B
Go
package entity
|
|
|
|
import (
|
|
"github.com/mohae/deepcopy"
|
|
"mongo.games.com/game/gamesrv/slotspkg/internal/generic/errors"
|
|
"mongo.games.com/game/gamesrv/slotspkg/internal/module/shared"
|
|
"reflect"
|
|
)
|
|
|
|
// GetCustom gets feature interface by feature ID
|
|
func (e *Entity) GetCustom(featureID int64) interface{} {
|
|
v, ok := e.Customs[featureID]
|
|
if !ok {
|
|
panic(errors.FeatureNotFound.Error())
|
|
}
|
|
return v
|
|
}
|
|
|
|
// AddFeatureCustom adds custom on feature
|
|
func (e *Entity) AddFeatureCustom(featureID int64, v interface{}) *shared.Feature {
|
|
v = deepcopy.Copy(v)
|
|
feature := e.GetFeature(featureID)
|
|
feature.Type = reflect.TypeOf(v).Elem().String()
|
|
_, ok := e.Customs[featureID]
|
|
if ok {
|
|
panic(errors.FeatureAlreadyExists.Error())
|
|
}
|
|
e.Customs[featureID] = v
|
|
return feature
|
|
}
|
|
|
|
// DeleteCustom deletes custom by feature id
|
|
func (e *Entity) DeleteCustom(featureID int64) {
|
|
delete(e.Customs, featureID)
|
|
}
|