本文整理汇总了Golang中github.com/cgrates/cgrates/utils.LCRKey函数的典型用法代码示例。如果您正苦于以下问题:Golang LCRKey函数的具体用法?Golang LCRKey怎么用?Golang LCRKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LCRKey函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetLCRFromStorage
func (cd *CallDescriptor) GetLCRFromStorage() (*LCR, error) {
keyVariants := []string{
utils.LCRKey(cd.Direction, cd.Tenant, cd.Category, cd.Account, cd.Subject),
utils.LCRKey(cd.Direction, cd.Tenant, cd.Category, cd.Account, utils.ANY),
utils.LCRKey(cd.Direction, cd.Tenant, cd.Category, utils.ANY, utils.ANY),
utils.LCRKey(cd.Direction, cd.Tenant, utils.ANY, utils.ANY, utils.ANY),
utils.LCRKey(utils.ANY, utils.ANY, cd.Category, utils.ANY, utils.ANY),
utils.LCRKey(utils.ANY, utils.ANY, utils.ANY, utils.ANY, utils.ANY),
}
if lcrSubjectPrefixMatching {
var partialSubjects []string
lenSubject := len(cd.Subject)
for i := 1; i < lenSubject; i++ {
partialSubjects = append(partialSubjects, utils.LCRKey(cd.Direction, cd.Tenant, cd.Category, cd.Account, cd.Subject[:lenSubject-i]))
}
// insert partialsubjects into keyVariants
keyVariants = append(keyVariants[:1], append(partialSubjects, keyVariants[1:]...)...)
}
for _, key := range keyVariants {
if lcr, err := ratingStorage.GetLCR(key, false, utils.NonTransactional); err != nil && err != utils.ErrNotFound {
return nil, err
} else if err == nil && lcr != nil {
return lcr, nil
}
}
return nil, utils.ErrNotFound
}
示例2: GetLCRFromStorage
func (cd *CallDescriptor) GetLCRFromStorage() (*LCR, error) {
keyVariants := []string{
utils.LCRKey(cd.Direction, cd.Tenant, cd.Category, cd.Account, cd.Subject),
utils.LCRKey(cd.Direction, cd.Tenant, cd.Category, cd.Account, utils.ANY),
utils.LCRKey(cd.Direction, cd.Tenant, cd.Category, utils.ANY, utils.ANY),
utils.LCRKey(cd.Direction, cd.Tenant, utils.ANY, utils.ANY, utils.ANY),
utils.LCRKey(cd.Direction, utils.ANY, utils.ANY, utils.ANY, utils.ANY),
utils.LCRKey(utils.ANY, utils.ANY, utils.ANY, utils.ANY, utils.ANY),
}
for _, key := range keyVariants {
if lcr, err := ratingStorage.GetLCR(key, false); err != nil && err != utils.ErrNotFound {
return nil, err
} else if err == nil {
return lcr, nil
}
}
return nil, utils.ErrNotFound
}
示例3: GetLcrRuleId
func (lcr *TpLcrRule) GetLcrRuleId() string {
return utils.LCRKey(lcr.Direction, lcr.Tenant, lcr.Category, lcr.Account, lcr.Subject)
}
示例4: LoadLCRs
func (tpr *TpReader) LoadLCRs() (err error) {
tps, err := tpr.lr.GetTpLCRs(&TpLcrRule{Tpid: tpr.tpid})
if err != nil {
return err
}
for _, tpLcr := range tps {
// check the rating profiles
ratingProfileSearchKey := utils.ConcatenatedKey(tpLcr.Direction, tpLcr.Tenant, tpLcr.RpCategory)
found := false
for rpfKey := range tpr.ratingProfiles {
if strings.HasPrefix(rpfKey, ratingProfileSearchKey) {
found = true
break
}
}
if !found && tpr.ratingStorage != nil {
if keys, err := tpr.ratingStorage.GetKeysForPrefix(utils.RATING_PROFILE_PREFIX + ratingProfileSearchKey); err != nil {
return fmt.Errorf("[LCR] error querying ratingDb %s", err.Error())
} else if len(keys) != 0 {
found = true
}
}
if !found {
return fmt.Errorf("[LCR] could not find ratingProfiles with prefix %s", ratingProfileSearchKey)
}
// check destination tags
if tpLcr.DestinationTag != "" && tpLcr.DestinationTag != utils.ANY {
_, found := tpr.destinations[tpLcr.DestinationTag]
if !found && tpr.ratingStorage != nil {
if found, err = tpr.ratingStorage.HasData(utils.DESTINATION_PREFIX, tpLcr.DestinationTag); err != nil {
return fmt.Errorf("[LCR] error querying ratingDb %s", err.Error())
}
}
if !found {
return fmt.Errorf("[LCR] could not find destination with tag %s", tpLcr.DestinationTag)
}
}
tag := utils.LCRKey(tpLcr.Direction, tpLcr.Tenant, tpLcr.Category, tpLcr.Account, tpLcr.Subject)
activationTime, _ := utils.ParseTimeDetectLayout(tpLcr.ActivationTime, tpr.timezone)
lcr, found := tpr.lcrs[tag]
if !found {
lcr = &LCR{
Direction: tpLcr.Direction,
Tenant: tpLcr.Tenant,
Category: tpLcr.Category,
Account: tpLcr.Account,
Subject: tpLcr.Subject,
}
}
var act *LCRActivation
for _, existingAct := range lcr.Activations {
if existingAct.ActivationTime.Equal(activationTime) {
act = existingAct
break
}
}
if act == nil {
act = &LCRActivation{
ActivationTime: activationTime,
}
lcr.Activations = append(lcr.Activations, act)
}
act.Entries = append(act.Entries, &LCREntry{
DestinationId: tpLcr.DestinationTag,
RPCategory: tpLcr.RpCategory,
Strategy: tpLcr.Strategy,
StrategyParams: tpLcr.StrategyParams,
Weight: tpLcr.Weight,
})
tpr.lcrs[tag] = lcr
}
return nil
}