From 33735613e793fa8a82d687ee8fbdf12a59dccc2e Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Tue, 3 Jun 2025 14:32:40 +0300 Subject: [PATCH] Rename Pool type to IPPool for clarity --- apis/loaders_it_test.go | 4 ++-- ips/ips_it_test.go | 2 +- utils/ips.go | 26 +++++++++++++------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apis/loaders_it_test.go b/apis/loaders_it_test.go index 59afa2d41..42d4f6a7e 100644 --- a/apis/loaders_it_test.go +++ b/apis/loaders_it_test.go @@ -1002,7 +1002,7 @@ func testLoadersGetIPProfiles(t *testing.T) { }, TTL: time.Second, Stored: true, - Pools: []*utils.Pool{ + Pools: []*utils.IPPool{ { ID: "POOL1", FilterIDs: []string{"*string:~*req.Destination:2001"}, @@ -1060,7 +1060,7 @@ func testLoadersGetIPProfiles(t *testing.T) { }, TTL: 2 * time.Second, Stored: false, - Pools: []*utils.Pool{ + Pools: []*utils.IPPool{ { ID: "POOL1", FilterIDs: []string{"*string:~*req.Destination:3001"}, diff --git a/ips/ips_it_test.go b/ips/ips_it_test.go index 0c5264f10..96ed1542e 100644 --- a/ips/ips_it_test.go +++ b/ips/ips_it_test.go @@ -152,7 +152,7 @@ cgrates.org,IPs2,*string:~*req.Account:1002,;20,2s,false,POOL1,*string:~*req.Des }, TTL: -1, Stored: false, - Pools: []*utils.Pool{ + Pools: []*utils.IPPool{ { ID: "FIRST_POOL", FilterIDs: []string{}, diff --git a/utils/ips.go b/utils/ips.go index 55a56731a..7241a6808 100644 --- a/utils/ips.go +++ b/utils/ips.go @@ -31,7 +31,7 @@ type IPProfile struct { Weights DynamicWeights TTL time.Duration Stored bool - Pools []*Pool + Pools []*IPPool } // IPProfileWithAPIOpts wraps IPProfile with APIOpts. @@ -50,7 +50,7 @@ func (p *IPProfile) Clone() *IPProfile { if p == nil { return nil } - pools := make([]*Pool, 0, len(p.Pools)) + pools := make([]*IPPool, 0, len(p.Pools)) for _, pool := range p.Pools { pools = append(pools, pool.Clone()) } @@ -102,7 +102,7 @@ func (p *IPProfile) Set(path []string, val any, newBranch bool) error { return nil } if len(p.Pools) == 0 || newBranch { - p.Pools = append(p.Pools, new(Pool)) + p.Pools = append(p.Pools, new(IPPool)) } pool := p.Pools[len(p.Pools)-1] return pool.Set(path[1:], val, newBranch) @@ -127,7 +127,7 @@ func (p *IPProfile) Merge(other any) { p.Stored = o.Stored } for _, pool := range o.Pools { - if idx := slices.IndexFunc(p.Pools, func(p *Pool) bool { + if idx := slices.IndexFunc(p.Pools, func(p *IPPool) bool { return p.ID == pool.ID }); idx != -1 { p.Pools[idx].Merge(pool) @@ -189,7 +189,7 @@ func IPProfileLockKey(tnt, id string) string { return ConcatenatedKey(CacheIPProfiles, tnt, id) } -type Pool struct { +type IPPool struct { ID string FilterIDs []string Type string @@ -201,11 +201,11 @@ type Pool struct { } // Clone creates a deep copy of Pool for thread-safe use. -func (p *Pool) Clone() *Pool { +func (p *IPPool) Clone() *IPPool { if p == nil { return nil } - return &Pool{ + return &IPPool{ ID: p.ID, FilterIDs: slices.Clone(p.FilterIDs), Type: p.Type, @@ -217,7 +217,7 @@ func (p *Pool) Clone() *Pool { } } -func (p *Pool) Set(path []string, val any, _ bool) error { +func (p *IPPool) Set(path []string, val any, _ bool) error { if len(path) != 1 { return ErrWrongPath } @@ -251,8 +251,8 @@ func (p *Pool) Set(path []string, val any, _ bool) error { return err } -func (p *Pool) Merge(other any) { - o := other.(*Pool) +func (p *IPPool) Merge(other any) { + o := other.(*IPPool) // NOTE: Merge gets called when the IDs are equal, so this is a no-op. // Kept for consistency with other components. @@ -277,9 +277,9 @@ func (p *Pool) Merge(other any) { p.Blockers = append(p.Blockers, o.Blockers...) } -func (p *Pool) String() string { return ToJSON(p) } +func (p *IPPool) String() string { return ToJSON(p) } -func (p *Pool) FieldAsString(fldPath []string) (string, error) { +func (p *IPPool) FieldAsString(fldPath []string) (string, error) { val, err := p.FieldAsInterface(fldPath) if err != nil { return "", err @@ -287,7 +287,7 @@ func (p *Pool) FieldAsString(fldPath []string) (string, error) { return IfaceAsString(val), nil } -func (p *Pool) FieldAsInterface(fldPath []string) (any, error) { +func (p *IPPool) FieldAsInterface(fldPath []string) (any, error) { if len(fldPath) == 0 { return p, nil }