1package grammar 2 3import ( 4 "github.com/splitio/go-split-commons/v3/dtos" 5 "github.com/splitio/go-toolkit/v4/injection" 6 "github.com/splitio/go-toolkit/v4/logging" 7) 8 9// Split struct with added logic that wraps around a DTO 10type Split struct { 11 splitData *dtos.SplitDTO 12 conditions []*Condition 13} 14 15// NewSplit instantiates a new Split object and all it's internal structures mapped to model classes 16func NewSplit(splitDTO *dtos.SplitDTO, ctx *injection.Context, logger logging.LoggerInterface) *Split { 17 conditions := make([]*Condition, 0) 18 for _, cond := range splitDTO.Conditions { 19 conditions = append(conditions, NewCondition(&cond, ctx, logger)) 20 } 21 22 split := Split{ 23 conditions: conditions, 24 splitData: splitDTO, 25 } 26 27 return &split 28} 29 30// Name returns the name of the feature 31func (s *Split) Name() string { 32 return s.splitData.Name 33} 34 35// Seed returns the seed use for hashing 36func (s *Split) Seed() int64 { 37 return s.splitData.Seed 38} 39 40// Status returns whether the split is active or arhived 41func (s *Split) Status() string { 42 status := s.splitData.Status 43 if status == "" || (status != SplitStatusActive && status != SplitStatusArchived) { 44 return SplitStatusActive 45 } 46 return status 47} 48 49// Killed returns whether the split has been killed or not 50func (s *Split) Killed() bool { 51 return s.splitData.Killed 52} 53 54// DefaultTreatment returns the default treatment for the current split 55func (s *Split) DefaultTreatment() string { 56 return s.splitData.DefaultTreatment 57} 58 59// TrafficAllocation returns the traffic allocation configured for the current split 60func (s *Split) TrafficAllocation() int { 61 return s.splitData.TrafficAllocation 62} 63 64// TrafficAllocationSeed returns the seed for traffic allocation configured for this split 65func (s *Split) TrafficAllocationSeed() int64 { 66 return s.splitData.TrafficAllocationSeed 67} 68 69// Algo returns the hashing algorithm configured for this split 70func (s *Split) Algo() int { 71 switch s.splitData.Algo { 72 case SplitAlgoLegacy: 73 return SplitAlgoLegacy 74 case SplitAlgoMurmur: 75 return SplitAlgoMurmur 76 default: 77 return SplitAlgoLegacy 78 } 79} 80 81// Conditions returns a slice of Condition objects 82func (s *Split) Conditions() []*Condition { 83 return s.conditions 84} 85 86// ChangeNumber returns the change number for this split 87func (s *Split) ChangeNumber() int64 { 88 return s.splitData.ChangeNumber 89} 90 91// Configurations returns the configurations for this split 92func (s *Split) Configurations() map[string]string { 93 return s.splitData.Configurations 94} 95