github.com/hzck/speedroute@v0.0.0-20201115191102-403b7d0e443f/model/reward.go (about) 1 package model 2 3 // Reward stores reward id, if it is unique and if can be counted as another reward via inheritance. 4 type Reward struct { 5 id string 6 unique bool 7 isA *Reward 8 canBe []*Reward 9 } 10 11 // ID returns reward id. 12 func (r *Reward) ID() string { 13 return r.id 14 } 15 16 // Unique returns if the reward is unique. 17 func (r *Reward) Unique() bool { 18 return r.unique 19 } 20 21 // IsA returns reference to inherited reward. 22 func (r *Reward) IsA() *Reward { 23 return r.isA 24 } 25 26 // CanBe returns all references which inherits this reward. 27 func (r *Reward) CanBe() []*Reward { 28 return r.canBe 29 } 30 31 // CreateReward constructs a new Reward. 32 func CreateReward(id string, unique bool, isa *Reward) *Reward { 33 reward := &Reward{id, unique, isa, nil} 34 if isa != nil { 35 isa.canBe = append(isa.canBe, reward) 36 } 37 return reward 38 }