mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Slightly optimize TenantID constructor
This commit is contained in:
committed by
Dan Christian Bogos
parent
eaeb04404e
commit
cdcf55f971
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user