From e7061d9ba45d4776f329790f3a31b75dc2592fd8 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Fri, 28 May 2021 10:40:50 +0300 Subject: [PATCH] Add & to utils.AttrReloadCacheWithAPIOpts 1.0 --- apis/cache.go | 6 +++--- apis/cache_it_test.go | 2 +- apis/cache_test.go | 2 +- apis/libadmin.go | 6 +++--- dispatchers/caches.go | 6 +++--- dispatchers/caches_it_test.go | 2 +- dispatchers/caches_test.go | 12 ++++++------ engine/caches.go | 8 ++++---- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/apis/cache.go b/apis/cache.go index 9ddb58229..cdf96147e 100644 --- a/apis/cache.go +++ b/apis/cache.go @@ -62,7 +62,7 @@ func (chSv1 *CacheSv1) RemoveItem(_ *context.Context, args *utils.ArgsGetCacheIt } // RemoveItems removes the Items with ID from cache -func (chSv1 *CacheSv1) RemoveItems(_ *context.Context, args utils.AttrReloadCacheWithAPIOpts, +func (chSv1 *CacheSv1) RemoveItems(_ *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) error { return chSv1.cacheS.V1RemoveItems(args, reply) } @@ -104,12 +104,12 @@ func (chSv1 *CacheSv1) RemoveGroup(args *utils.ArgsGetGroupWithAPIOpts, // // ReloadCache reloads cache from DB for a prefix or completely func (chSv1 *CacheSv1) ReloadCache(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { - return chSv1.cacheS.V1ReloadCache(ctx, *args, reply) + return chSv1.cacheS.V1ReloadCache(ctx, args, reply) } // LoadCache loads cache from DB for a prefix or completely func (chSv1 *CacheSv1) LoadCache(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { - return chSv1.cacheS.V1LoadCache(ctx, *args, reply) + return chSv1.cacheS.V1LoadCache(ctx, args, reply) } // ReplicateSet replicate an item diff --git a/apis/cache_it_test.go b/apis/cache_it_test.go index 0059681f5..904f27431 100644 --- a/apis/cache_it_test.go +++ b/apis/cache_it_test.go @@ -371,7 +371,7 @@ func testCacheSRemoveItemsAndReloadCache(t *testing.T) { } //remove all items - argsRemove := utils.AttrReloadCacheWithAPIOpts{ + argsRemove := &utils.AttrReloadCacheWithAPIOpts{ ArgsCache: map[string][]string{ utils.AttributeProfileIDs: {"cgrates.org:TEST_ATTRIBUTES_IT_TEST"}, }, diff --git a/apis/cache_test.go b/apis/cache_test.go index 57ea0afcd..6a6b47c06 100644 --- a/apis/cache_test.go +++ b/apis/cache_test.go @@ -133,7 +133,7 @@ func TestCacheSetAndRemoveItems(t *testing.T) { ch.SetWithoutReplicate(utils.CacheAttributeProfiles, "cgrates.org:TestCacheSetAndRemoveItems3", nil, nil, true, utils.NonTransactional) cache := NewCacheSv1(ch) - argsRemItm := utils.AttrReloadCacheWithAPIOpts{ + argsRemItm := &utils.AttrReloadCacheWithAPIOpts{ ArgsCache: map[string][]string{ utils.AttributeProfileIDs: {"cgrates.org:TestCacheSetAndRemoveItems1", "cgrates.org:TestCacheSetAndRemoveItems2", "cgrates.org:TestCacheSetAndRemoveItems3"}, diff --git a/apis/libadmin.go b/apis/libadmin.go index 855bddb25..070aec1ee 100644 --- a/apis/libadmin.go +++ b/apis/libadmin.go @@ -235,7 +235,7 @@ func (apierSv1 *AdminS) callCacheMultiple(cacheopt, tnt, cacheID string, itemIDs return case utils.MetaReload: method = utils.CacheSv1ReloadCache - args = utils.AttrReloadCacheWithAPIOpts{ + args = &utils.AttrReloadCacheWithAPIOpts{ Tenant: tnt, ArgsCache: map[string][]string{ utils.CacheInstanceToArg[cacheID]: itemIDs, @@ -244,7 +244,7 @@ func (apierSv1 *AdminS) callCacheMultiple(cacheopt, tnt, cacheID string, itemIDs } case utils.MetaLoad: method = utils.CacheSv1LoadCache - args = utils.AttrReloadCacheWithAPIOpts{ + args = &utils.AttrReloadCacheWithAPIOpts{ Tenant: tnt, ArgsCache: map[string][]string{ utils.CacheInstanceToArg[cacheID]: itemIDs, @@ -253,7 +253,7 @@ func (apierSv1 *AdminS) callCacheMultiple(cacheopt, tnt, cacheID string, itemIDs } case utils.MetaRemove: method = utils.CacheSv1RemoveItems - args = utils.AttrReloadCacheWithAPIOpts{ + args = &utils.AttrReloadCacheWithAPIOpts{ Tenant: tnt, ArgsCache: map[string][]string{ utils.CacheInstanceToArg[cacheID]: itemIDs, diff --git a/dispatchers/caches.go b/dispatchers/caches.go index 831b20bcd..a44107e4a 100644 --- a/dispatchers/caches.go +++ b/dispatchers/caches.go @@ -124,7 +124,7 @@ func (dS *DispatcherService) CacheSv1RemoveItem(args *utils.ArgsGetCacheItemWith } // CacheSv1RemoveItems removes the Item with ID from cache -func (dS *DispatcherService) CacheSv1RemoveItems(args utils.AttrReloadCacheWithAPIOpts, +func (dS *DispatcherService) CacheSv1RemoveItems(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -255,7 +255,7 @@ func (dS *DispatcherService) CacheSv1RemoveGroup(args *utils.ArgsGetGroupWithAPI } // CacheSv1ReloadCache reloads cache from DB for a prefix or completely -func (dS *DispatcherService) CacheSv1ReloadCache(args utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { +func (dS *DispatcherService) CacheSv1ReloadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -273,7 +273,7 @@ func (dS *DispatcherService) CacheSv1ReloadCache(args utils.AttrReloadCacheWithA } // CacheSv1LoadCache loads cache from DB for a prefix or completely -func (dS *DispatcherService) CacheSv1LoadCache(args utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { +func (dS *DispatcherService) CacheSv1LoadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant diff --git a/dispatchers/caches_it_test.go b/dispatchers/caches_it_test.go index a234aff83..cad92920f 100644 --- a/dispatchers/caches_it_test.go +++ b/dispatchers/caches_it_test.go @@ -112,7 +112,7 @@ func testDspChcLoadAfterFolder(t *testing.T) { } reply := "" // Simple test that command is executed without errors - if err := dispEngine.RPC.Call(utils.CacheSv1LoadCache, utils.AttrReloadCacheWithAPIOpts{ + if err := dispEngine.RPC.Call(utils.CacheSv1LoadCache, &utils.AttrReloadCacheWithAPIOpts{ APIOpts: map[string]interface{}{ utils.OptsAPIKey: "chc12345", }, diff --git a/dispatchers/caches_test.go b/dispatchers/caches_test.go index 653aa10e6..d7cd7f308 100644 --- a/dispatchers/caches_test.go +++ b/dispatchers/caches_test.go @@ -185,7 +185,7 @@ func TestDspCacheSv1RemoveItemsError(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} - CGREvent := utils.AttrReloadCacheWithAPIOpts{} + CGREvent := &utils.AttrReloadCacheWithAPIOpts{} var reply *string result := dspSrv.CacheSv1RemoveItems(CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" @@ -197,7 +197,7 @@ func TestDspCacheSv1RemoveItemsError(t *testing.T) { func TestDspCacheSv1RemoveItemsArgsNil(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) - CGREvent := utils.AttrReloadCacheWithAPIOpts{ + CGREvent := &utils.AttrReloadCacheWithAPIOpts{ Tenant: "tenant", } var reply *string @@ -374,7 +374,7 @@ func TestDspCacheSv1ReloadCacheError(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} - CGREvent := utils.AttrReloadCacheWithAPIOpts{} + CGREvent := &utils.AttrReloadCacheWithAPIOpts{} var reply *string result := dspSrv.CacheSv1ReloadCache(CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" @@ -386,7 +386,7 @@ func TestDspCacheSv1ReloadCacheError(t *testing.T) { func TestDspCacheSv1ReloadCacheNil(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) - CGREvent := utils.AttrReloadCacheWithAPIOpts{ + CGREvent := &utils.AttrReloadCacheWithAPIOpts{ Tenant: "tenant", } var reply *string @@ -401,7 +401,7 @@ func TestDspCacheSv1LoadCacheError(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} - CGREvent := utils.AttrReloadCacheWithAPIOpts{} + CGREvent := &utils.AttrReloadCacheWithAPIOpts{} var reply *string result := dspSrv.CacheSv1LoadCache(CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" @@ -413,7 +413,7 @@ func TestDspCacheSv1LoadCacheError(t *testing.T) { func TestDspCacheSv1LoadCacheNil(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) - CGREvent := utils.AttrReloadCacheWithAPIOpts{ + CGREvent := &utils.AttrReloadCacheWithAPIOpts{ Tenant: "tenant", } var reply *string diff --git a/engine/caches.go b/engine/caches.go index afb6be61a..6c76da777 100644 --- a/engine/caches.go +++ b/engine/caches.go @@ -287,7 +287,7 @@ func (chS *CacheS) V1RemoveItem(args *utils.ArgsGetCacheItemWithAPIOpts, return } -func (chS *CacheS) V1RemoveItems(args utils.AttrReloadCacheWithAPIOpts, +func (chS *CacheS) V1RemoveItems(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { for key, ids := range args.ArgsCache { if cacheID, has := utils.ArgCacheToInstance[key]; has { @@ -356,15 +356,15 @@ func (chS *CacheS) V1RemoveGroup(args *utils.ArgsGetGroupWithAPIOpts, return } -func (chS *CacheS) V1ReloadCache(ctx *context.Context, attrs utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { +func (chS *CacheS) V1ReloadCache(ctx *context.Context, attrs *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { return chS.cacheDataFromDB(ctx, attrs, reply, true) } -func (chS *CacheS) V1LoadCache(ctx *context.Context, attrs utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { +func (chS *CacheS) V1LoadCache(ctx *context.Context, attrs *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { return chS.cacheDataFromDB(ctx, attrs, reply, false) } -func (chS *CacheS) cacheDataFromDB(ctx *context.Context, attrs utils.AttrReloadCacheWithAPIOpts, reply *string, mustBeCached bool) (err error) { +func (chS *CacheS) cacheDataFromDB(ctx *context.Context, attrs *utils.AttrReloadCacheWithAPIOpts, reply *string, mustBeCached bool) (err error) { for key, ids := range attrs.ArgsCache { if prfx, has := utils.ArgCacheToPrefix[key]; has { if err = chS.dm.CacheDataFromDB(ctx, prfx, ids, mustBeCached); err != nil {