本文整理匯總了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
}