From cdcf55f9719bc270bdda0b8d0f6c7cb651752096 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Wed, 6 Mar 2024 12:04:48 -0500 Subject: [PATCH] Slightly optimize TenantID constructor --- utils/coreutils.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/utils/coreutils.go b/utils/coreutils.go index dc1dd975e..0fc79836b 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -776,12 +776,15 @@ func GetCGRVersion() (vers string, err error) { return fmt.Sprintf("%s@%s-%s-%s", CGRateS, Version, commitDate.UTC().Format("20060102150405"), commitHash[:12]), nil } -func NewTenantID(tntID string) *TenantID { - if !strings.Contains(tntID, ConcatenatedKeySep) { // no :, ID without Tenant - return &TenantID{ID: tntID} +// NewTenantID parses a string in the format of "tenant:ID" and returns +// a TenantID struct. If the separator is not found, the entire string +// is treated as the ID. +func NewTenantID(input string) *TenantID { + tenant, id, sepFound := strings.Cut(input, ConcatenatedKeySep) + if !sepFound { + return &TenantID{ID: input} } - tIDSplt := strings.SplitN(tntID, ConcatenatedKeySep, 2) - return &TenantID{Tenant: tIDSplt[0], ID: tIDSplt[1]} + return &TenantID{Tenant: tenant, ID: id} } type PaginatorWithTenant struct {