mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 14:48:43 +05:00
Replacing IsSliceMember ,CloneStringSlice and SliceStringEqual with slices package functions
This commit is contained in:
committed by
Dan Christian Bogos
parent
65310e7437
commit
32ed816de7
@@ -21,6 +21,7 @@ package engine
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -202,7 +203,7 @@ func (alS *AttributeS) processEvent(ctx *context.Context, tnt string, args *util
|
||||
}
|
||||
substitute := utils.IfaceAsString(out)
|
||||
//add only once the Path in AlteredFields
|
||||
if !utils.IsSliceMember(rply.AlteredFields[0].Fields, attribute.Path) {
|
||||
if !slices.Contains(rply.AlteredFields[0].Fields, attribute.Path) {
|
||||
rply.AlteredFields[0].Fields = append(rply.AlteredFields[0].Fields, attribute.Path)
|
||||
}
|
||||
if attribute.Path == utils.MetaTenant {
|
||||
|
||||
@@ -20,6 +20,7 @@ package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/baningo"
|
||||
@@ -894,7 +895,7 @@ func (dm *DataManager) SetStatQueueProfile(ctx *context.Context, sqp *StatQueueP
|
||||
for _, metric := range sqp.Metrics { // add missing metrics and recreate the old metrics that changed
|
||||
cMetricIDs.Add(metric.MetricID)
|
||||
if oSqMetric, has := oSq.SQMetrics[metric.MetricID]; !has ||
|
||||
!utils.SliceStringEqual(oSqMetric.GetFilterIDs(), metric.FilterIDs) { // recreate it if the filter changed
|
||||
!slices.Equal(oSqMetric.GetFilterIDs(), metric.FilterIDs) { // recreate it if the filter changed
|
||||
if oSq.SQMetrics[metric.MetricID], err = NewStatMetric(metric.MetricID,
|
||||
uint64(sqp.MinItems), metric.FilterIDs); err != nil {
|
||||
return
|
||||
|
||||
@@ -20,6 +20,7 @@ package engine
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -45,7 +46,7 @@ func (dC *DispatcherHostProfile) Clone() (cln *DispatcherHostProfile) {
|
||||
Blocker: dC.Blocker,
|
||||
}
|
||||
if dC.FilterIDs != nil {
|
||||
cln.FilterIDs = utils.CloneStringSlice(dC.FilterIDs)
|
||||
cln.FilterIDs = slices.Clone(dC.FilterIDs)
|
||||
}
|
||||
if dC.Params != nil {
|
||||
cln.Params = make(map[string]any)
|
||||
|
||||
@@ -20,6 +20,7 @@ package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
@@ -122,7 +123,7 @@ func (eeR *ExportRequest) SetFields(ctx *context.Context, tplFlds []*config.FCTe
|
||||
return
|
||||
} else if fullPath == nil { // no dynamic path
|
||||
fullPath = &utils.FullPath{
|
||||
PathSlice: utils.CloneStringSlice(tplFld.GetPathSlice()), // need to clone so me do not modify the template
|
||||
PathSlice: slices.Clone(tplFld.GetPathSlice()), // need to clone so me do not modify the template
|
||||
Path: tplFld.Path,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"net"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -292,7 +293,7 @@ func (fltr *FilterRule) IsValid() bool {
|
||||
if fltr.Element == utils.EmptyString {
|
||||
return fltr.Type == utils.MetaNever
|
||||
}
|
||||
if len(fltr.Values) == 0 && !utils.IsSliceMember([]string{utils.MetaExists, utils.MetaNotExists,
|
||||
if len(fltr.Values) == 0 && !slices.Contains([]string{utils.MetaExists, utils.MetaNotExists,
|
||||
utils.MetaEmpty, utils.MetaNotEmpty}, fltr.Type) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
@@ -37,7 +38,7 @@ func GetFloat64Opts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS *Fi
|
||||
}
|
||||
evDP := ev.AsDataProvider()
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, evDP); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
@@ -60,7 +61,7 @@ func GetDurationOpts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS *F
|
||||
}
|
||||
evDP := ev.AsDataProvider()
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, evDP); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
@@ -83,7 +84,7 @@ func GetStringOpts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS *Fil
|
||||
}
|
||||
evDP := ev.AsDataProvider()
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, evDP); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
@@ -106,7 +107,7 @@ func GetTimeOpts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS *Filte
|
||||
}
|
||||
evDP := ev.AsDataProvider()
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
var pass bool
|
||||
@@ -130,7 +131,7 @@ func GetStringSliceOpts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS
|
||||
}
|
||||
evDP := ev.AsDataProvider()
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, evDP); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
@@ -157,7 +158,7 @@ func GetIntOpts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS *Filter
|
||||
}
|
||||
evDP := ev.AsDataProvider()
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, evDP); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
@@ -188,7 +189,7 @@ func GetBoolOpts(ctx *context.Context, tnt string, dP utils.DataProvider, fS *Fi
|
||||
}
|
||||
}
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, dP); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
@@ -211,7 +212,7 @@ func GetDecimalBigOpts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS
|
||||
}
|
||||
evDP := ev.AsDataProvider()
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, evDP); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
@@ -234,7 +235,7 @@ func GetInterfaceOpts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS *
|
||||
}
|
||||
evDP := ev.AsDataProvider()
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, evDP); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
@@ -261,7 +262,7 @@ func GetIntPointerOpts(ctx *context.Context, tnt string, ev *utils.CGREvent, fS
|
||||
}
|
||||
evDP := ev.AsDataProvider()
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, evDP); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
@@ -294,7 +295,7 @@ func GetDurationPointerOptsFromMultipleMaps(ctx *context.Context, tnt string, ev
|
||||
utils.MetaReq: eventStart,
|
||||
}
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, evMS); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
@@ -327,7 +328,7 @@ func GetDurationOptsFromMultipleMaps(ctx *context.Context, tnt string, eventStar
|
||||
utils.MetaReq: eventStart,
|
||||
}
|
||||
for _, opt := range dynOpts { // iterate through the options
|
||||
if !utils.IsSliceMember([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
if !slices.Contains([]string{utils.EmptyString, utils.MetaAny, tnt}, opt.Tenant) {
|
||||
continue
|
||||
}
|
||||
if pass, err := fS.Pass(ctx, tnt, opt.FilterIDs, evMS); err != nil { // check if the filter is passing for the DataProvider and return the option if it does
|
||||
|
||||
@@ -20,6 +20,7 @@ package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -482,7 +483,7 @@ func getRevFltrIdxHealthFromReverse(ctx *context.Context, dm *DataManager, fltrC
|
||||
}
|
||||
return
|
||||
}
|
||||
if !utils.IsSliceMember(filterIDs, fltrID) { // check the filters
|
||||
if !slices.Contains(filterIDs, fltrID) { // check the filters
|
||||
key := utils.ConcatenatedKey(tnt, id)
|
||||
rply[indxType].BrokenReverseIndexes[key] = append(rply[indxType].BrokenReverseIndexes[key], fltrID)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package engine
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -78,7 +79,7 @@ func TestComputeIndexes(t *testing.T) {
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return utils.SliceStringPointer(utils.CloneStringSlice(th.FilterIDs)), nil
|
||||
return utils.SliceStringPointer(slices.Clone(th.FilterIDs)), nil
|
||||
}, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -116,7 +117,7 @@ func TestComputeIndexesIDsNotNil(t *testing.T) {
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return utils.SliceStringPointer(utils.CloneStringSlice(th.FilterIDs)), nil
|
||||
return utils.SliceStringPointer(slices.Clone(th.FilterIDs)), nil
|
||||
}, nil)
|
||||
if err != utils.ErrNotFound {
|
||||
t.Errorf("Expected %v\n but received %v", utils.ErrNotFound, err)
|
||||
@@ -3035,7 +3036,7 @@ func TestComputeIndexesNilFilterIDs(t *testing.T) {
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return utils.SliceStringPointer(utils.CloneStringSlice(th.FilterIDs)), nil
|
||||
return utils.SliceStringPointer(slices.Clone(th.FilterIDs)), nil
|
||||
}, nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -3089,7 +3090,7 @@ func TestComputeIndexesNewFilterIndexErr(t *testing.T) {
|
||||
|
||||
_, err := ComputeIndexes(context.Background(), dm, "cgrates.org", utils.EmptyString, utils.CacheThresholdFilterIndexes,
|
||||
&[]string{"THD_2"}, utils.NonTransactional, func(tnt, id, grp string) (*[]string, error) {
|
||||
return utils.SliceStringPointer(utils.CloneStringSlice(thd.FilterIDs)), nil
|
||||
return utils.SliceStringPointer(slices.Clone(thd.FilterIDs)), nil
|
||||
}, nil)
|
||||
if err != utils.ErrNotImplemented {
|
||||
t.Errorf("\nExpected error <%+v>, \nReceived error <%+v>", utils.ErrNotImplemented, err)
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -199,7 +200,7 @@ func InitStorDB(cfg *config.CGRConfig) error {
|
||||
dbPath)); err != nil {
|
||||
return err
|
||||
}
|
||||
if utils.IsSliceMember([]string{utils.MetaMongo, utils.MetaMySQL, utils.MetaPostgres},
|
||||
if slices.Contains([]string{utils.MetaMongo, utils.MetaMySQL, utils.MetaPostgres},
|
||||
cfg.StorDbCfg().Type) {
|
||||
if err := SetDBVersions(storDB); err != nil {
|
||||
return err
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -1605,7 +1606,7 @@ func DispatcherProfileToAPI(dpp *DispatcherProfile) (tpDPP *utils.TPDispatcherPr
|
||||
for i, host := range dpp.Hosts {
|
||||
tpDPP.Hosts[i] = &utils.TPDispatcherHostProfile{
|
||||
ID: host.ID,
|
||||
FilterIDs: utils.CloneStringSlice(host.FilterIDs),
|
||||
FilterIDs: slices.Clone(host.FilterIDs),
|
||||
Weight: host.Weight,
|
||||
Params: make([]any, len(host.Params)),
|
||||
Blocker: host.Blocker,
|
||||
|
||||
@@ -20,6 +20,7 @@ package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/cgrates/birpc/context"
|
||||
"github.com/ericlagergren/decimal"
|
||||
@@ -65,7 +66,7 @@ func populateCostForRoutes(ctx *context.Context, cfg *config.CGRConfig, connMgr
|
||||
if len(route.AccountIDs) != 0 { // query AccountS for cost
|
||||
|
||||
var acntCost utils.EventCharges
|
||||
ev.APIOpts[utils.OptsAccountsProfileIDs] = utils.CloneStringSlice(route.AccountIDs)
|
||||
ev.APIOpts[utils.OptsAccountsProfileIDs] = slices.Clone(route.AccountIDs)
|
||||
if err = connMgr.Call(ctx, cfg.RouteSCfg().AccountSConns,
|
||||
utils.AccountSv1MaxAbstracts, ev, &acntCost); err != nil {
|
||||
if extraOpts.ignoreErrors {
|
||||
@@ -90,7 +91,7 @@ func populateCostForRoutes(ctx *context.Context, cfg *config.CGRConfig, connMgr
|
||||
}
|
||||
srtRoute.SortingData[utils.AccountIDs] = acntIDs
|
||||
} else { // query RateS for cost
|
||||
ev.APIOpts[utils.OptsRatesProfileIDs] = utils.CloneStringSlice(route.RateProfileIDs)
|
||||
ev.APIOpts[utils.OptsRatesProfileIDs] = slices.Clone(route.RateProfileIDs)
|
||||
var rpCost utils.RateProfileCost
|
||||
if err = connMgr.Call(ctx, cfg.RouteSCfg().RateSConns,
|
||||
utils.RateSv1CostForEvent, ev, &rpCost); err != nil {
|
||||
|
||||
@@ -20,6 +20,7 @@ package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -457,7 +458,7 @@ func (ddc *StatDDC) Clone() StatMetric {
|
||||
Count: ddc.Count,
|
||||
Events: make(map[string]map[string]uint64),
|
||||
MinItems: ddc.MinItems,
|
||||
FilterIDs: utils.CloneStringSlice(ddc.FilterIDs),
|
||||
FilterIDs: slices.Clone(ddc.FilterIDs),
|
||||
}
|
||||
for k, v := range ddc.Events {
|
||||
cln.Events[k] = make(map[string]uint64)
|
||||
@@ -606,7 +607,7 @@ func (sum *Metric) Clone() (cln *Metric) {
|
||||
Count: sum.Count,
|
||||
Events: make(map[string]*DecimalWithCompress),
|
||||
MinItems: sum.MinItems,
|
||||
FilterIDs: utils.CloneStringSlice(sum.FilterIDs),
|
||||
FilterIDs: slices.Clone(sum.FilterIDs),
|
||||
}
|
||||
for k, v := range sum.Events {
|
||||
cln.Events[k] = &(*v)
|
||||
@@ -836,7 +837,7 @@ func (dst *StatDistinct) Clone() StatMetric {
|
||||
MinItems: dst.MinItems,
|
||||
FieldName: dst.FieldName,
|
||||
FieldValues: make(map[string]utils.StringSet),
|
||||
FilterIDs: utils.CloneStringSlice(dst.FilterIDs),
|
||||
FilterIDs: slices.Clone(dst.FilterIDs),
|
||||
}
|
||||
for k, v := range dst.Events {
|
||||
cln.Events[k] = make(map[string]uint64)
|
||||
|
||||
@@ -3773,7 +3773,9 @@ func TestAttributesV1ProcessEvent(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
|
||||
}
|
||||
if !reflect.DeepEqual(expected, rply) {
|
||||
if sort.Slice(rply.AlteredFields[0].Fields, func(i, j int) bool {
|
||||
return rply.AlteredFields[0].Fields[i] < rply.AlteredFields[0].Fields[j]
|
||||
}); !reflect.DeepEqual(expected, rply) {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ToJSON(expected), utils.ToJSON(rply))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user